Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
- #AutoIt3Wrapper_UseUpx=n
- #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
- #include <WindowsConstants.au3>
- #include <GuiConstantsEx.au3>
- #include <EditConstants.au3>
- #include <GUIConstants.au3>
- #include <WinAPI.au3>
- #include <Color.au3>
- #include <Misc.au3>
- If (Not HotKeySet("{F9}", "Nothing")) Then
- MsgBox(16, "Error", "Could not register the F9 hotkey.")
- Exit
- EndIf
- If (Not HotKeySet("{F10}", "Quit")) Then
- MsgBox(16, "Error", "Could not register the F10 hotkey.")
- Exit
- EndIf
- Global $iX1, $iY1, $iX2, $iY2, $aPos, $sMsg, $sBMP_Path
- Global $threshold, $memDc
- Global $image, $GUI, $drwstate = False
- Global $width
- Global $height
- Global $pixels
- Global $pathString = "12345678"
- Global $scramble = False
- Global $rotate = 0
- Global $speed
- #Region ### START Koda GUI section ### Form=
- $hMain_GUI = GUICreate("Drawball Buddy", 258, 75, 782, 291)
- GUICtrlCreateTab(0, 0, 257, 73)
- GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
- GUICtrlCreateTabItem("Functions")
- $Slider1 = GUICtrlCreateSlider(44, 25, 209, 17)
- GUICtrlSetLimit(-1, 45, 3)
- $Slider2 = GUICtrlCreateSlider(44, 49, 209, 17)
- GUICtrlSetLimit(-1, 45, 3)
- $Paint_X = GUICtrlCreateButton("Paint", 4, 25, 41, 17, $WS_GROUP)
- $DrawBtn = GUICtrlCreateButton("Trace", 4, 49, 41, 17, $WS_GROUP)
- GUICtrlCreateTabItem("About")
- GUICtrlCreateLabel("Author: THAT1ANONYMOUSDUDE", 16, 24, 177, 17)
- GUICtrlCreateLabel("Web: AutoRepo.tk", 16, 48, 93, 17)
- GUICtrlCreateTabItem("")
- GUISetState(@SW_SHOW)
- #EndRegion ### END Koda GUI section ###
- While 1
- Switch GUIGetMsg()
- Case $GUI_EVENT_CLOSE
- FileDelete(@ScriptDir & "\Rect.bmp")
- Exit
- Case $Paint_X
- GUISetState(@SW_HIDE, $hMain_GUI)
- _Region_Select()
- TrayTip("Painting Canvas", 'Press "F10" to stop', 5, 1)
- _Draw()
- GUISetState(@SW_SHOW, $hMain_GUI)
- Case $DrawBtn
- GUISetState(@SW_HIDE, $hMain_GUI)
- $imageFile = FileOpenDialog("Select Image", @WorkingDir, "Images (*.jpg;*.jpeg;*.gif;*.png;*.bmp)", 1)
- _Imagedraw()
- GUISetState(@SW_SHOW, $hMain_GUI)
- GUICtrlSetState($DrawBtn, $GUI_DISABLE)
- EndSwitch
- WEnd
- Func _Draw()
- ;Sleep(2000)
- For $y = $iY1 To $iY2 Step +GUICtrlRead($Slider1)
- For $x = $iX1 To $iX2 Step +GUICtrlRead($Slider2)
- BlockInput(1)
- MouseClick('LEFT', $x, $y, 1, 1)
- BlockInput(0)
- Sleep(1)
- If $drwstate Then ExitLoop
- Next
- If $drwstate Then ExitLoop
- Next
- $drwstate = False
- Return 1
- EndFunc ;==>_Draw
- ; -------------
- Func _Region_Select()
- Local $aMouse_Pos, $hMask, $hMaster_Mask, $iTemp
- Local $UserDLL = DllOpen("user32.dll")
- Global $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
- _GUICreateInvRect($hRectangle_GUI, 0, 0, 1, 1)
- GUISetBkColor(0)
- WinSetTrans($hRectangle_GUI, "", 50)
- GUISetState(@SW_SHOW, $hRectangle_GUI)
- GUISetCursor(3, 1, $hRectangle_GUI)
- ; Wait until mouse button pressed
- While Not _IsPressed("01", $UserDLL)
- Sleep(10)
- WEnd
- ; Get first mouse position
- $aMouse_Pos = MouseGetPos()
- $iX1 = $aMouse_Pos[0]
- $iY1 = $aMouse_Pos[1]
- ; Draw rectangle while mouse button pressed
- While _IsPressed("01", $UserDLL)
- $aMouse_Pos = MouseGetPos()
- ; Set in correct order if required
- If $aMouse_Pos[0] < $iX1 Then
- $iX_Pos = $aMouse_Pos[0]
- $iWidth = $iX1 - $aMouse_Pos[0]
- Else
- $iX_Pos = $iX1
- $iWidth = $aMouse_Pos[0] - $iX1
- EndIf
- If $aMouse_Pos[1] < $iY1 Then
- $iY_Pos = $aMouse_Pos[1]
- $iHeight = $iY1 - $aMouse_Pos[1]
- Else
- $iY_Pos = $iY1
- $iHeight = $aMouse_Pos[1] - $iY1
- EndIf
- _GUICreateInvRect($hRectangle_GUI, $iX_Pos, $iY_Pos, $iWidth, $iHeight)
- Sleep(10)
- WEnd
- ; Get second mouse position
- $iX2 = $aMouse_Pos[0]
- $iY2 = $aMouse_Pos[1]
- ; Set in correct order if required
- If $iX2 < $iX1 Then
- $iTemp = $iX1
- $iX1 = $iX2
- $iX2 = $iTemp
- EndIf
- If $iY2 < $iY1 Then
- $iTemp = $iY1
- $iY1 = $iY2
- $iY2 = $iTemp
- EndIf
- GUIDelete($hRectangle_GUI)
- DllClose($UserDLL)
- EndFunc ;==>_Region_Select
- Func _GUICreateInvRect($hWnd, $iX, $iY, $iW, $iH)
- $hMask_1 = _WinAPI_CreateRectRgn(0, 0, @DesktopWidth, $iY)
- $hMask_2 = _WinAPI_CreateRectRgn(0, 0, $iX, @DesktopHeight)
- $hMask_3 = _WinAPI_CreateRectRgn($iX + $iW, 0, @DesktopWidth, @DesktopHeight)
- $hMask_4 = _WinAPI_CreateRectRgn(0, $iY + $iH, @DesktopWidth, @DesktopHeight)
- _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_2, 2)
- _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_3, 2)
- _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_4, 2)
- _WinAPI_DeleteObject($hMask_2)
- _WinAPI_DeleteObject($hMask_3)
- _WinAPI_DeleteObject($hMask_4)
- _WinAPI_SetWindowRgn($hWnd, $hMask_1, 1)
- EndFunc ;==>_GUICreateInvRect
- ;////////////////////////////////////////////////
- Func _Imagedraw()
- ;; Options dialog ;;
- $optGUI = GUICreate("Settings", 190, 270, -1, -1, $WS_CAPTION, BitOR($WS_EX_APPWINDOW, $WS_EX_TOOLWINDOW))
- GUICtrlCreateGroup("Image processing", 10, 5, 150, 85)
- GUICtrlCreateLabel("Sensitivity (0~255):", 10, 28, 110, 15)
- $thresholdInput = GUICtrlCreateInput("100", 115, 25, 35, 20, $ES_NUMBER)
- GUICtrlCreateLabel("Width (px):", 10, 48, 110, 15)
- $widthInput = GUICtrlCreateInput("100", 115, 45, 35, 20, $ES_NUMBER)
- GUICtrlCreateLabel("Height (px):", 10, 68, 110, 15)
- $heightInput = GUICtrlCreateInput("100", 115, 65, 35, 20, $ES_NUMBER)
- GUICtrlCreateGroup("Drawing pattern", 5, 95, 150, 140)
- $horizontalRadio = GUICtrlCreateRadio("Horizontal", 10, 115, 110, 15)
- $verticalRadio = GUICtrlCreateRadio("Vertical", 10, 135, 110, 15)
- $diagonalRadio = GUICtrlCreateRadio("Diagonal", 10, 155, 110, 15)
- $rotateRadio = GUICtrlCreateRadio("Spiral", 10, 175, 110, 15)
- $scrambleRadio = GUICtrlCreateRadio("Random", 10, 195, 110, 15)
- GUICtrlSetState($diagonalRadio, $GUI_CHECKED)
- GUICtrlCreateLabel("Mouse speed (0~100):", 10, 213, 110, 15)
- $speedInput = GUICtrlCreateInput("0", 125, 210, 25, 20, $ES_NUMBER)
- $okBtn = GUICtrlCreateButton("Ok", 30, 245, 40, 20)
- $cancelBtn = GUICtrlCreateButton("Cancel", 80, 245, 50, 20)
- GUISetState()
- While 1
- Switch (GUIGetMsg())
- Case $GUI_EVENT_CLOSE
- Exit
- Case $cancelBtn
- Exit
- Case $okBtn
- $threshold = GUICtrlRead($thresholdInput)
- $width = GUICtrlRead($widthInput)
- $height = GUICtrlRead($heightInput)
- $speed = GUICtrlRead($speedInput)
- If (GUICtrlRead($horizontalRadio) == $GUI_CHECKED) Then
- $pathString = "45273618"
- ElseIf (GUICtrlRead($verticalRadio) == $GUI_CHECKED) Then
- $pathString = "27453618"
- ElseIf (GUICtrlRead($diagonalRadio) == $GUI_CHECKED) Then
- $pathString = "36184527"
- ElseIf (GUICtrlRead($rotateRadio) == $GUI_CHECKED) Then
- $pathString = "14678532"
- $rotate = 1
- ElseIf (GUICtrlRead($scrambleRadio) == $GUI_CHECKED) Then
- $scramble = True
- EndIf
- GUIDelete($optGUI)
- ExitLoop
- EndSwitch
- WEnd
- ;; Processing dialog ;;
- $GUI = GUICreate("Processing image...", $width, $height + 20, -1, -1, $WS_CAPTION, BitOR($WS_EX_APPWINDOW, $WS_EX_TOOLWINDOW))
- GUISetBkColor(0xffffff)
- $imageBox = GUICtrlCreatePic($imageFile, 0, 0, $width, $height)
- $progress = GUICtrlCreateProgress(0, $height, $width, 20)
- GUISetState()
- ;; Get image pixels ;;
- $dc = _WinAPI_GetDC($GUI)
- $memDc = _WinAPI_CreateCompatibleDC($dc)
- $bitmap = _WinAPI_CreateCompatibleBitmap($dc, $width, $height)
- _WinAPI_SelectObject($memDc, $bitmap)
- _WinAPI_BitBlt($memDc, 0, 0, $width, $height, $dc, 0, 0, $SRCCOPY)
- $bits = DllStructCreate("dword[" & ($width * $height) & "]")
- DllCall("gdi32", "int", "GetBitmapBits", "ptr", $bitmap, "int", ($width * $height * 4), "ptr", DllStructGetPtr($bits))
- GUICtrlDelete($imageBox)
- ;; Process the pixels ;;
- Dim $pixels[$width][$height]
- For $y = 0 To ($height - 1)
- For $x = 0 To ($width - 1)
- $index = ($y * $width) + $x
- $color = DllStructGetData($bits, 1, $index)
- $red = _ColorGetBlue($color)
- $green = _ColorGetGreen($color)
- $blue = _ColorGetRed($color)
- $shade = ($red + $green + $blue) / 3
- If ($shade > $threshold) Then
- $color = 0xffffff
- $pixels[$x][$y] = 0
- Else
- $color = 0
- $pixels[$x][$y] = 1
- EndIf
- DllStructSetData($bits, 1, $color, $index)
- Next
- DllCall("gdi32", "int", "SetBitmapBits", "ptr", $bitmap, "int", ($width * $height * 4), "ptr", DllStructGetPtr($bits))
- _WinAPI_BitBlt($dc, 0, 0, $width, $height, $memDc, 0, 0, $SRCCOPY)
- GUICtrlSetData($progress, ($y * 100) / $height)
- Next
- _WinAPI_ReleaseDC($GUI, $dc)
- GUIRegisterMsg($WM_PAINT, "OnPaint")
- ;; Ready to draw ;;
- TrayTip("Image Ready", "Press 'F9' to print at mouse position, 'F10' to quit.", 10)
- HotKeySet("{F9}", "Draw")
- HotKeySet("{F10}", "Quit")
- Return 1
- EndFunc ;==>_Imagedraw
- Func OnPaint($hwndGUI, $msgID, $wParam, $lParam)
- Local $paintStruct = DllStructCreate("hwnd hdc;int fErase;dword rcPaint[4];int fRestore;int fIncUpdate;byte rgbReserved[32]")
- $dc = DllCall("user32", "hwnd", "BeginPaint", "hwnd", $hwndGUI, "ptr", DllStructGetPtr($paintStruct))
- $dc = $dc[0]
- _WinAPI_BitBlt($dc, 0, 0, $width, $height, $memDc, 0, 0, $SRCCOPY)
- DllCall("user32", "hwnd", "EndPaint", "hwnd", $hwndGUI, "ptr", DllStructGetPtr($paintStruct))
- Return $GUI_RUNDEFMSG
- EndFunc ;==>OnPaint
- Func Draw()
- $mouseCenter = MouseGetPos()
- $x0 = $mouseCenter[0] - ($width / 2)
- $y0 = $mouseCenter[1] - ($height / 2)
- ;; Draw all the areas ;;
- $stack = CreateStack(1000)
- For $y = 0 To ($height - 1)
- For $x = 0 To ($width - 1)
- If ($pixels[$x][$y] == 1) Then
- BlockInput(1)
- MouseMove($x + $x0, $y + $y0, $speed)
- MouseDown("primary")
- DrawArea($stack, $x, $y, $x0, $y0)
- MouseUp("primary")
- BlockInput(0)
- Else
- EndIf
- If $drwstate Then ExitLoop
- Next
- If $drwstate Then ExitLoop
- Next
- $drwstate = False
- ;; Reset the pixels statuses ;;
- For $y = 0 To ($height - 1) Step 1
- For $x = 0 To ($width - 1) Step 1
- If ($pixels[$x][$y] == 2) Then
- $pixels[$x][$y] = 1
- EndIf
- Next
- Next
- EndFunc ;==>Draw
- Func DrawArea(ByRef $stack, $x, $y, $x0, $y0)
- Local $path[8]
- Local $continue
- $path = StringSplit($pathString, "")
- While 1
- MouseMove($x + $x0, $y + $y0, $speed)
- $pixels[$x][$y] = 2
- If ($scramble) Then ScramblePath($path)
- If ($rotate > 0) Then RotatePath($path, $rotate)
- ;;;;;;;;;;;;;;;;;;;
- ;; +---+---+---+ ;;
- ;; | 1 | 2 | 3 | ;;
- ;; +---+---+---+ ;;
- ;; | 4 | | 5 | ;;
- ;; +---+---+---+ ;;
- ;; | 6 | 7 | 8 | ;;
- ;; +---+---+---+ ;;
- ;;;;;;;;;;;;;;;;;;;
- $continue = False
- For $i = 0 To 7
- Switch ($path[$i])
- Case 1
- If (($x > 0) And ($y > 0)) Then
- If ($pixels[$x - 1][$y - 1] == 1) Then
- Push($stack, $x, $y)
- $x -= 1
- $y -= 1
- $continue = True
- ExitLoop
- EndIf
- EndIf
- Case 2
- If ($y > 0) Then
- If ($pixels[$x][$y - 1] == 1) Then
- Push($stack, $x, $y)
- $y -= 1
- $continue = True
- ExitLoop
- EndIf
- EndIf
- Case 3
- If (($x > 0) And ($y < 0)) Then
- If ($pixels[$x + 1][$y - 1] == 1) Then
- Push($stack, $x, $y)
- $x += 1
- $y -= 1
- $continue = True
- ExitLoop
- EndIf
- EndIf
- Case 4
- If ($x > 0) Then
- If ($pixels[$x - 1][$y] == 1) Then
- Push($stack, $x, $y)
- $x -= 1
- $continue = True
- ExitLoop
- EndIf
- EndIf
- Case 5
- If ($x < ($width - 1)) Then
- If ($pixels[$x + 1][$y] == 1) Then
- Push($stack, $x, $y)
- $x += 1
- $continue = True
- ExitLoop
- EndIf
- EndIf
- Case 6
- If (($x < 0) And ($y > 0)) Then
- If ($pixels[$x - 1][$y + 1] == 1) Then
- Push($stack, $x, $y)
- $x -= 1
- $y += 1
- $continue = True
- ExitLoop
- EndIf
- EndIf
- Case 7
- If ($y < ($height - 1)) Then
- If ($pixels[$x][$y + 1] == 1) Then
- Push($stack, $x, $y)
- $y += 1
- $continue = True
- ExitLoop
- EndIf
- EndIf
- Case 8
- If (($x < ($width - 1)) And ($y < ($height - 1))) Then
- If ($pixels[$x + 1][$y + 1] == 1) Then
- Push($stack, $x, $y)
- $x += 1
- $y += 1
- $continue = True
- ExitLoop
- EndIf
- EndIf
- EndSwitch
- Next
- If ($continue) Then ContinueLoop
- If (Not Pop($stack, $x, $y)) Then ExitLoop
- WEnd
- EndFunc ;==>DrawArea
- Func ScramblePath(ByRef $path)
- Local $table = "12345678"
- Local $newPath[8]
- For $i = 8 To 1 Step -1
- $next = StringMid($table, Random(1, $i, 1), 1)
- $newPath[$i - 1] = Number($next)
- $table = StringReplace($table, $next, "")
- Next
- $path = $newPath
- EndFunc ;==>ScramblePath
- Func RotatePath(ByRef $path, $places)
- If ($places == 0) Then
- Return $path
- Else
- For $i = 1 To Abs($places)
- $temp = $path[7]
- $path[7] = $path[6]
- $path[6] = $path[5]
- $path[5] = $path[4]
- $path[4] = $path[3]
- $path[3] = $path[2]
- $path[2] = $path[1]
- $path[1] = $path[0]
- $path[0] = $temp
- Next
- EndIf
- EndFunc ;==>RotatePath
- Func CreateStack($size)
- Dim $stack[$size + 1][2]
- $stack[0][0] = 0
- $stack[0][1] = $size
- Return $stack
- EndFunc ;==>CreateStack
- Func Push(ByRef $stack, $x, $y)
- $stack[0][0] += 1
- If ($stack[0][0] > $stack[0][1]) Then
- $stack[0][1] += 1000
- ReDim $stack[$stack[0][1] + 1][2]
- EndIf
- $stack[$stack[0][0]][0] = $x
- $stack[$stack[0][0]][1] = $y
- EndFunc ;==>Push
- Func Pop(ByRef $stack, ByRef $x, ByRef $y)
- If ($stack[0][0] < 1) Then
- Return False
- EndIf
- $x = $stack[$stack[0][0]][0]
- $y = $stack[$stack[0][0]][1]
- $stack[0][0] -= 1
- Return True
- EndFunc ;==>Pop
- Func Nothing()
- EndFunc ;==>Nothing
- Func Quit()
- BlockInput(0)
- MouseUp("primary")
- $drwstate = True
- TrayTip("Operation Halt", "All Bot Operations Have Benn Halted", 3, 1)
- EndFunc ;==>Quit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement