Skip to content

Instantly share code, notes, and snippets.

@kistaaa
Created April 17, 2018 13:35
Show Gist options
  • Save kistaaa/d1b28c1265dcd073f8f648e4b4e915b2 to your computer and use it in GitHub Desktop.
Save kistaaa/d1b28c1265dcd073f8f648e4b4e915b2 to your computer and use it in GitHub Desktop.
Fractal Tree AutoIT
#include <AutoItConstants.au3>
; THESE 3 VARS ARE ALL YOU NEED LOL
; starting branch length
$startLength = 350
; angle to twist the tree
$startAngle = 45
; minimum branch size
$minLength = 20
$PI = 3.141592653589793
$centerX = @DesktopWidth / 2
; bottom vertical excluding windows bar
$centerY = @DesktopHeight - 50
Func calculate($type, $pos, $len, $angle)
local $rads = $angle * $PI / 180
If $type == 'x' Then
Return $pos + Sin($rads) * $len
ElseIf $type == 'y' Then
Return $pos - Cos($rads) * $len
EndIf
EndFunc
Func draw($startX, $startY, $len, $angle)
; move mouse to position
MouseMove($startX, $startY)
; click
MouseDown($MOUSE_CLICK_LEFT)
; convert angle/lenght to X/Y coords
local $currentX = calculate('x', $startX, $len, $angle)
local $currentY = calculate('y', $startY, $len, $angle)
; draw
MouseMove( $currentX , $currentY , 1 )
; release
MouseUp($MOUSE_CLICK_LEFT)
; stop when branch size reaches minimum
If $len < $minLength Then
Return
EndIf
; reduce lenght by golden ratio
$len *= 0.618
; split branch in 2
; left branch
draw($currentX , $currentY, $len, $angle - $startAngle);
; right branch
draw($currentX , $currentY, $len, $angle + $startAngle);
EndFunc
; start
draw($centerX, $centerY, $startLength, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment