11require 'forwardable'
22
3- # Here we use our own Vec2D class, until we create a path as an array of TVec2D
4- # toxis Vec2D. Required to use the ToxicLibsSupport lineStrip2D method .
5- # further we can and should use power of ruby to make Branch enumerable and
6- # Forwardable to define which enumerable methods we want to use
3+ # Here we use the JRubyArt Vec2D class, and not toxis Vec2D. We avoid using
4+ # ToxicLibsSupport, by using our own AppRender to translate Vec2D to vertices .
5+ # Further we use the power of ruby (metaprogramming) to make Branch enumerable
6+ # and use Forwardable to define which enumerable methods we want to use.
77class Branch
88 include Enumerable
99 extend Forwardable
@@ -29,7 +29,7 @@ def initialize(app, pos, dir, speed)
2929 @children = [ ]
3030 @xbound = Boundary . new ( 0 , app . width )
3131 @ybound = Boundary . new ( 0 , app . height )
32- path << TVec2D . new ( pos . x , pos . y )
32+ path << pos
3333 end
3434
3535 def run
@@ -39,12 +39,12 @@ def run
3939
4040 private
4141
42- # Note use of both rotate! (changes original) rotate (returns a copy) of Vec2D
42+ # NB: use of both rotate! (changes original) rotate (returns a copy) of Vec2D
4343 def grow
4444 check_bounds ( position + ( dir * speed ) ) if path . length < MAX_LEN
4545 @position += ( dir * speed )
4646 dir . rotate! ( rand ( -0.5 ..0.5 ) * THETA )
47- path << TVec2D . new ( position . x , position . y )
47+ path << position
4848 if ( length < MAX_GEN ) && ( rand < BRANCH_CHANCE )
4949 branch_dir = dir . rotate ( rand ( -0.5 ..0.5 ) * BRANCH_THETA )
5050 self << Branch . new ( app , position . copy , branch_dir , speed * 0.99 )
@@ -53,7 +53,11 @@ def grow
5353 end
5454
5555 def display
56- app . gfx . lineStrip2D ( path )
56+ app . begin_shape
57+ app . stroke ( 255 )
58+ app . no_fill
59+ path . each { |vec | vec . to_vertex ( app . renderer ) }
60+ app . end_shape
5761 each ( &:display )
5862 end
5963
@@ -66,6 +70,6 @@ def check_bounds(pos)
6670# we are looking for excluded values
6771Boundary = Struct . new ( :lower , :upper ) do
6872 def exclude? ( val )
69- true unless ( lower ...upper ) . cover? val
73+ ! ( lower ...upper ) . cover? val
7074 end
7175end
0 commit comments