<%# # Fractal tree rubyish example. Usage: # % nqp-p rubyish.nqp examples-rubyish/fractal-tree.rbi > fractal.svg # %> <%#---------- def cos(a); nqp::cos_n(a); end def sin(a); nqp::sin_n(a); end @scale = 0.66 @PI = 3.1415926535 @eps = 2.0 def tree(x1, y1, len, angle = 1.5 * @PI) x2 = x1 + len * cos(angle) y2 = y1 + len * sin(angle) sw = len > 20? len / 10 : 2; g = len < @eps*2? 210: 20; puts " " if (len *= @scale) >= @eps then tree(x2, y2, len, angle + 0.2*@PI); tree(x2, y2, len, angle - 0.2*@PI); end end width = 1000 height = 850 tree(x1=width/2, y1=height, length=300) #-----------%>