Skip to content

Instantly share code, notes, and snippets.

@glurp
Created September 10, 2011 13:39
Show Gist options
  • Save glurp/1208318 to your computer and use it in GitHub Desktop.
Save glurp/1208318 to your computer and use it in GitHub Desktop.
Green shoes fractal, (from rosettacode.org)
require 'green_shoes'
Shoes.app(:title => "Fractal Tree", :width => 600, :height => 600) do
background "#000".."#777"
stroke "#000"
@deg_to_rad = Math::PI / 180.0
C=%w{AA0 EE0 FF0 EE0 EE8 EF8 8F8 7F7 0F0 5BB 0FF FAA}
def drawTree(x1, y1, angle, depth)
return if depth <= rand(2)
s=3+rand(4)
x2 = x1 + (Math.cos(angle * @deg_to_rad) * depth * s).to_i
y2 = y1 + (Math.sin(angle * @deg_to_rad) * depth * s).to_i
stroke "##{C[(C.size-depth)%C.size]}"
line x1, y1, x2, y2
drawTree(x2, y2, angle - 10-rand(10), depth - 1)
drawTree(x2, y2, angle + 10+rand(10), depth - 1)
end
drawTree(300,550,-90,12)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment