Browse Source

add support for non-deterministic rules

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

10
lindenmayer-system/lindenmeyer-system.html

@ -195,11 +195,8 @@ function sierpinski() { @@ -195,11 +195,8 @@ function sierpinski() {
var r = generate(
'iIjJX',
[
['X', 'F[-lfX][cfX][+rfX]'],
//['F'.split(''), 'FF'.split('')],
//['L'.split(''), 'LL'.split('')],
//['C'.split(''), 'CC'.split('')],
//['R'.split(''), 'RR'.split('')],
//['X', 'F[-lfX][.cfX][+rfX]'],
['X', ['F[-lfX][.cfX][+rfX]', 'F[-lfX]m[.cfX][+rfX]']],
],
8
);
@ -210,6 +207,7 @@ function sierpinski() { @@ -210,6 +207,7 @@ function sierpinski() {
{
'F': draw_forward(),
'f': draw_forward(0.5),
'm': draw_forward(0.5),
'l': draw_stepsize_mul(0.7),
'c': draw_stepsize_mul(0.8),
@ -220,9 +218,9 @@ function sierpinski() { @@ -220,9 +218,9 @@ function sierpinski() {
'j': draw_set_turn_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(0.1),
'[': draw_state_push(),
']': draw_state_pop(),
}

6
lindenmayer-system/lindenmeyer-system.js

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

Loading…
Cancel
Save