Did you miss your activation email?

• Thursday April 22, 2021, 7:30 am
• Proudly celebrating 15+ years online.
• Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.

### Author Topic: Drawing Shapes in AHK (Proof-of-Concept)  (Read 4380 times)

#### Masonjar13

• Participant
• Joined in 2014
• Posts: 35
##### Drawing Shapes in AHK (Proof-of-Concept)
« on: August 24, 2014, 02:51 AM »
I wrote a function for someone on one of the AHK forums to get coords based off known coords, length, and angle. I then decided to play into it a bit and draw some shapes. Here's a pretty good demo I made, although, please note that for polygons, it will never have more inner-vectors compared to the outer-vectors, because I wanted it that way

Instructions:
•  Run script
•  Open a new paint window, full-screen
•  The rest should be self-explanatory (starting coords are always the center of the screen)
AHK-Draw Demo
Code: Autohotkey [Select]
1. CoordMode, Mouse, Screen
2. Process,Priority,,R
3.
4. ; Make Gui's
5. Gui,1:Add,Button,gCircle w130 h50,Circle
6. Gui,1:Add,Button,gPolygon w130 h50,Polygon
7. Gui,1:Add,Button,gSpiral w130 h50,Spiral
13. Gui,3:Add,Text,ym,Narrowness (1 - 100):
20. Gui,4:Add,Text,ym,Outward vectors (count):
22. Gui,4:Add,Text,,`nInward vectors (count):
27.
28. ; main gui
29. +1::
30. Gui,1:Show,,Draw
31. return
32.
33. Circle: ; circle gui
34. Gui,2:Show,,Draw Circle
35. return
36. CircleOK: ; draw circle
37.
38. Loop 361
39. {
40.     GetPosFromAngle(mx,my,A_ScreenWidth/2,A_ScreenHeight/2,len,A_Index)
41.     MouseMove,% mx,% my,0
42.     if(A_Index=1)
43.         Send {LButton down}
44. }
45. Send {LButton up}
46. BlockInput MouseMoveOff
47. return
48.
49. Spiral: ; spiral gui
50. Gui,3:Show,,Draw Spiral
51. return
52. SpiralOK: ; draw spiral
53. ind:=0
54. Send {LButton down}
55.
56. Loop %Lcnt%
57. {
58.     Loop 360
59.     {
60.         ind++
61.         GetPosFromAngle(mx,my,A_ScreenWidth/2,A_ScreenHeight/2,ind*(Narrow*0.01),A_Index)
62.         MouseMove,% mx,% my,0
63.     }
64. }
65. Send {LButton up}
66. BlockInput MouseMoveOff
67. return
68.
69. Polygon: ; polygon gui
70. Gui,4:Show,,Draw Polygon
71. return
72. PolygonOk: ; draw polygon
73. if(Ovec+Ivec > 360){
74.     msgbox,,Error,Can not have more than 360 vectors.
75.     return
76. }
77. ind:=0
78.
80. MouseMove,% mx,% my,0
81. Send {LButton down}
82. Lpc:= Ovec + Ivec
83. Ovec--
84. iys:=1
85.
86. Loop % Lpc
87. {
88.     ind+=360/Lpc
90.     MouseMove,% mx,% my,0
91.     Ivec-=iys ? 1 : 0
92.     Ovec-=!iys ? 1 : 0
93.     iys:=Ivec < 1 ? 0 : !iys
94.     Sleep 15 ; seems to be inconsistent during multiple runs without delay
95. }
96. Send {LButton up}
97. BlockInput MouseMoveOff
98. return
99.
100. +2:: ; stop drawing
101. if(GetKeyState("LButton"))
102.     Send {LButton up}
103.
104. +3:: ; kill
105. if(GetKeyState("LButton"))
106.     Send {LButton up}
107.
108. ; ***function(s)***
109.
110. GetPosFromAngle(ByRef x2,ByRef y2,x1,y1,len,ang){
111.     ang := (ang-90) * 0.0174532925
112.     x2 := x1 + len * cos(ang)
113.     y2 := y1 + len * sin(ang)
114. }

Demo pics

The hotkeys are Shift+1 to bring up the main gui, Shift+2 to instantly interrupt the drawing, Shift+3 to kill the script.

I encourage modification of this code, but request acknowledgement if my function is used elsewhere, thanks!
Tox ID: 065459DFC23CA5D238F2334168150B8727B1D0826C80DD2F49F35B612B401A0837F89E7C9C86
« Last Edit: August 24, 2014, 10:51 PM by Masonjar13 »

• First Author