samples/processing_app/basics/structure/recursion1.rb in ruby-processing-1.0.11 vs samples/processing_app/basics/structure/recursion1.rb in ruby-processing-2.4.1

- old
+ new

@@ -2,41 +2,26 @@ # # A demonstration of recursion, which means functions call themselves. # Notice how the drawCircle() function calls itself at the end of its block. # It continues to do this until the variable "level" is equal to 1. -class Recursion1 < Processing::App - def setup - - size 200, 200 - - no_stroke - smooth - no_loop - end - - def draw - - draw_circle 126, 170, 6 - end - - def draw_circle ( x, radius, level ) - - tt = 126 * level / 4.0 - - fill tt - - ellipse x, 100, radius*2, radius*2 - - if level > 1 - - level = level - 1 - - draw_circle x - radius/2, radius/2, level - draw_circle x + radius/2, radius/2, level - end - end - +def setup + size 640, 360 + no_stroke + no_loop end -Recursion1.new :title => "Recursion1" \ No newline at end of file +def draw + draw_circle width / 2, 280, 6 +end + +def draw_circle ( x, radius, level ) + tt = 126 * level / 4.0 + fill tt + ellipse x, height / 2, radius*2, radius*2 + if level > 1 + level = level - 1 + draw_circle x - radius/2, radius/2, level + draw_circle x + radius/2, radius/2, level + end +end