Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • September 27, 2016, 05:30:21 AM
  • Proudly celebrating 10 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.
  • donate

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

Masonjar13

  • Participant
  • Joined in 2014
  • *
  • Posts: 35
    • View Profile
    • Read more about this member.
    • Donate to Member
Drawing Shapes in AHK (Proof-of-Concept)
« on: August 24, 2014, 02:51:35 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  :Thmbsup:

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
  8. Gui,2:Add,Text,,Radius:
  9. Gui,2:Add,Edit,vlen Limit4,
  10. Gui,2:Add,Button,gCircleOK,Draw!
  11. Gui,3:Add,Text,,Layer count:
  12. Gui,3:Add,Edit,vLcnt Limit5,
  13. Gui,3:Add,Text,ym,Narrowness (1 - 100):
  14. Gui,3:Add,Edit,vNarrow Limit3,
  15. Gui,3:Add,Button,gSpiralOk,Draw!
  16. Gui,4:Add,Text,,Outward radius:
  17. Gui,4:Add,Edit,vOrad Limit4,
  18. Gui,4:Add,Text,,`nInward radius:
  19. Gui,4:Add,Edit,vIrad Limit4,
  20. Gui,4:Add,Text,ym,Outward vectors (count):
  21. Gui,4:Add,Edit,vOvec Limit3,
  22. Gui,4:Add,Text,,`nInward vectors (count):
  23. Gui,4:Add,Edit,vIvec Limit3,
  24. Gui,4:Add,Text,ym,Angle:
  25. Gui,4:Add,Edit,vPang Limit4,
  26. Gui,4:Add,Button,gPolygonOk,Draw!
  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.  
  79. GetPosFromAngle(mx,my,A_ScreenWidth/2,A_ScreenHeight/2,Orad,Pang)
  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
  89.     GetPosFromAngle(mx,my,A_ScreenWidth/2,A_ScreenHeight/2,iys?Irad:Orad,ind+Pang)
  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!  8)
Tox ID: 065459DFC23CA5D238F2334168150B8727B1D0826C80DD2F49F35B612B401A0837F89E7C9C86
« Last Edit: August 24, 2014, 10:51:24 PM by Masonjar13 »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,254
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Drawing Shapes in AHK (Proof-of-Concept)
« Reply #1 on: August 25, 2014, 07:59:04 AM »
neat.  :up: