Class: TexPlay::LSystem
Overview
L-System code adding LSystem class to TexPlay module
Instance Method Summary collapse
- #angle(new_angle = nil) ⇒ Object
- #atom(new_atom) ⇒ Object
-
#initialize(&block) ⇒ LSystem
constructor
A new instance of LSystem.
- #produce_string(order) ⇒ Object
- #rule(new_rule) ⇒ Object
Constructor Details
#initialize(&block) ⇒ LSystem
Returns a new instance of LSystem.
78 79 80 81 82 |
# File 'lib/texplay-contrib.rb', line 78 def initialize(&block) @rules = {} instance_eval(&block) if block end |
Instance Method Details
#angle(new_angle = nil) ⇒ Object
92 93 94 95 |
# File 'lib/texplay-contrib.rb', line 92 def angle(new_angle=nil) return @angle if !new_angle @angle = new_angle end |
#atom(new_atom) ⇒ Object
88 89 90 |
# File 'lib/texplay-contrib.rb', line 88 def atom(new_atom) @atom = new_atom end |
#produce_string(order) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/texplay-contrib.rb', line 97 def produce_string(order) order = order[:order] string = @atom.dup order.times do i = 0 while(i < string.length) sub = @rules[string[i, 1]] string[i] = sub if sub i += sub ? sub.length : 1 end end string end |
#rule(new_rule) ⇒ Object
84 85 86 |
# File 'lib/texplay-contrib.rb', line 84 def rule(new_rule) @rules.merge!(new_rule) end |