Sha256: ba3a20d4c5c5476715a91ca9a8274c2e9bcaba0c2f3e3df5916f9e829d51ec08
Contents?: true
Size: 613 Bytes
Versions: 8
Compression:
Stored size: 613 Bytes
Contents
############################ # Simple lsystem grammar ############################ class Grammar attr_reader :axiom, :rules def initialize(axiom, rules) @axiom = axiom @rules = rules end def expand(production, iterations, &block) production.each_char do |token| if rules.key?(token) && iterations > 0 expand(rules[token], iterations - 1, &block) else yield token end end end def each(gen) expand(axiom, gen) { |token| yield token } end def generate(gen) output = [] each(gen) { |token| output << token } return output end end
Version data entries
8 entries across 8 versions & 2 rubygems