Browse Source

add support for functions in production rules

master
Fr3deric 6 years ago
parent
commit
b7e304433a
  1. 8
      lindenmayer-system/lindenmeyer-system.js

8
lindenmayer-system/lindenmeyer-system.js

@ -20,7 +20,13 @@ function generate(start, rules, iterations) { @@ -20,7 +20,13 @@ function generate(start, rules, iterations) {
while(pos < start.length) {
let w = start.slice(pos, pos + rule[0].length);
if(startswith(w, rule[0])) {
start.splice(pos, rule[0].length, rule[1])
var ruleres;
if(typeof rule[1] == 'function') {
ruleres = rule[1]();
} else {
ruleres = rule[1];
}
start.splice(pos, rule[0].length, ruleres)
pos += rule[0].length;
} else {
pos += 1;

Loading…
Cancel
Save