class Lindenmayer::LSystem
Lindenmayer
System
Public Class Methods
new(axiom, productions, options = {})
click to toggle source
# File lib/lsystem.rb, line 8 def initialize(axiom, productions, options = {}) @axiom = axiom @random = options[:random] @productions = productions.map do |key, transform| k, production = if key.match(/[<>]/) cs_prod = ContextSensitiveProduction.new(key, transform, random: @random) [cs_prod.key, cs_prod] else [key, Production.new(transform, random: @random)] end [k, production] end.to_h end
Public Instance Methods
iterate(count = 1)
click to toggle source
# File lib/lsystem.rb, line 23 def iterate(count = 1) count.times do @axiom = @axiom.split('').each_with_index.map do |c, c_idx| if @productions[c] @productions[c].transform(c_idx, @axiom) else c end end.join end @axiom end