Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
colored the fractal tree
  • Loading branch information
dwarring committed Oct 16, 2013
1 parent 8ca5f43 commit 49838b9
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions examples/rubyish/rubyish-examples/fractal-tree.rbi
@@ -1,31 +1,31 @@
<?rbi?>
<%# Fractal tree example %>
<%# % nqp rubyish.nqp rubyish-examples/fractal-tree.rbi > fractal.svg %>
<%# Fractal tree example #%>
<%# % nqp rubyish.nqp rubyish-examples/fractal-tree.rbi > fractal.svg #%>
<?xml version='1.0' encoding='utf-8' standalone='no'?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN'
'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
<svg width='100%' height='100%' version='1.1'
xmlns='http://www.w3.org/2000/svg'>

<%#----------
@scale = 6/10
@scale = 0.66
@PI = 3.1415926535
@eps = 2.0
def tree(x, y, len, angle)
if len >= 1.0 then
x2 = x + len * nqp::cos_n(angle)
y2 = y + len * nqp::sin_n(angle)
puts "<line x1='#{x}' y1='#{y}' x2='#{x2}' y2='#{y2}' style='stroke:rgb(0,0,0);stroke-width:1'/>";
tree(x2, y2, len*@scale, angle + @PI/5);
tree(x2, y2, len*@scale, angle - @PI/5);
if len >= @eps then
x2 = x + len * nqp::cos_n(angle)
y2 = y + len * nqp::sin_n(angle)
sw = len > 20? len / 10 : 2;
g = len < @eps*2? 210: 20;
puts " <line x1='#{x}' y1='#{y}' x2='#{x2}' y2='#{y2}' style='stroke:rgb(130,#{g},80);stroke-width:#{sw}'/>" \
if x >= 0.0 and y >= 0.0
tree(x2, y2, len*@scale, angle + 0.2*@PI);
tree(x2, y2, len*@scale, angle - 0.2*@PI);
end
end

width = 1000
height = 1000
length = 400

tree(width/2, height, length, 3*@PI/2)
width = 1000
height = 850
tree(x=width/2, y=height, length=300, angle=1.5*@PI)
#-----------%>

</svg>

0 comments on commit 49838b9

Please sign in to comment.