Browse Source

add support for non-deterministic rules

master
Fr3deric 5 years ago
parent
commit
40a1fc2425
  1. 10
      lindenmayer-system/lindenmeyer-system.html
  2. 4
      lindenmayer-system/lindenmeyer-system.js

10
lindenmayer-system/lindenmeyer-system.html

@ -195,11 +195,8 @@ function sierpinski() {
var r = generate( var r = generate(
'iIjJX', 'iIjJX',
[ [
['X', 'F[-lfX][cfX][+rfX]'], //['X', 'F[-lfX][.cfX][+rfX]'],
//['F'.split(''), 'FF'.split('')], ['X', ['F[-lfX][.cfX][+rfX]', 'F[-lfX]m[.cfX][+rfX]']],
//['L'.split(''), 'LL'.split('')],
//['C'.split(''), 'CC'.split('')],
//['R'.split(''), 'RR'.split('')],
], ],
8 8
); );
@ -210,6 +207,7 @@ function sierpinski() {
{ {
'F': draw_forward(), 'F': draw_forward(),
'f': draw_forward(0.5), 'f': draw_forward(0.5),
'm': draw_forward(0.5),
'l': draw_stepsize_mul(0.7), 'l': draw_stepsize_mul(0.7),
'c': draw_stepsize_mul(0.8), 'c': draw_stepsize_mul(0.8),
@ -220,9 +218,9 @@ function sierpinski() {
'j': draw_set_turn_noise(1), 'j': draw_set_turn_noise(1),
'J': draw_set_length_noise(1), 'J': draw_set_length_noise(1),
'*': draw_angle_add((Math.random() - 0.5) * 0.01),
'-': draw_angle_turn(-1), '-': draw_angle_turn(-1),
'+': draw_angle_turn(1), '+': draw_angle_turn(1),
'.': draw_angle_turn(0.1),
'[': draw_state_push(), '[': draw_state_push(),
']': draw_state_pop(), ']': draw_state_pop(),
} }

4
lindenmayer-system/lindenmeyer-system.js

@ -25,6 +25,10 @@ function generate(start, rules, iterations) {
var ruleres; var ruleres;
if(typeof rule[1] == 'function') { if(typeof rule[1] == 'function') {
ruleres = rule[1](); ruleres = rule[1]();
} else if(typeof rule[1] == 'object') {
var r = Math.floor(Math.random() * rule[1].length);
console.log(r);
ruleres = rule[1][r];
}else { }else {
ruleres = rule[1]; ruleres = rule[1];
} }

Loading…
Cancel
Save