1+ # Using abbreviated lsystem syntax NB: 9 = 10 repeats and 3 = 4 repeats
12class PenroseSnowflake
23 include Processing ::Proxy
34
45 attr_accessor :axiom , :grammar , :start_length , :theta , :production ,
56 :draw_length , :pos
6- DELTA = PI / 10
7+ DELTA = PI / 5 # 36 degrees
78
89 def initialize ( pos )
9- @axiom = 'F3-F3-F3-F3 -F'
10- @grammar = Grammar . new ( axiom , 'F' => 'F3-F3-F45 -F++F3 -F' )
10+ @axiom = 'F2-F2-F2-F2 -F'
11+ @grammar = Grammar . new ( axiom , 'F' => 'F2-F2-F5 -F+F2 -F' )
1112 @start_length = 450.0
1213 @theta = 0
1314 @pos = pos
@@ -20,30 +21,30 @@ def initialize(pos)
2021 ##############################################################################
2122
2223 def render
23- repeats = 1
24+ repeat = 1
2425 production . each do |element |
2526 case element
2627 when 'F'
2728 new_pos = pos + Vec2D . from_angle ( theta ) * draw_length
2829 line ( pos . x , pos . y , new_pos . x , new_pos . y )
2930 @pos = new_pos
30- repeats = 1
31+ repeat = 1
3132 when '+'
32- @theta += DELTA * repeats
33- repeats = 1
33+ @theta += DELTA * repeat
34+ repeat = 1
3435 when '-'
35- @theta -= DELTA * repeats
36- repeats = 1
37- when '3' , '4 ', '5'
38- repeats + = element . to_i
36+ @theta -= DELTA * repeat
37+ repeat = 1
38+ when '2 ' , '5'
39+ repeat = element . to_i
3940 else
4041 puts "Character '#{ element } ' is not in grammar"
4142 end
4243 end
4344 end
4445
4546 ##########################################
46- # adjust draw length with number of repeats
47+ # adjust draw length with number of repeat
4748 # uses grammar to set production string
4849 # see 'grammar.rb'
4950 ##########################################
0 commit comments