Browse Source

represent words as strings instead of arrays

master
Fr3deric 5 years ago
parent
commit
ad236f0e51
  1. 37
      lindenmayer-system/lindenmeyer-system.html
  2. 4
      lindenmayer-system/lindenmeyer-system.js

37
lindenmayer-system/lindenmeyer-system.html

@ -30,10 +30,10 @@ var r = generate('A'.split(''), @@ -30,10 +30,10 @@ var r = generate('A'.split(''),
function dragon_curve(variant) {
project.clear();
var r = generate(
'FX'.split(''),
'FX',
[
['X'.split(''), 'X+YF+'.split('')],
['Y'.split(''), '-FX-Y'.split('')]
['X', 'X+YF+'],
['Y', '-FX-Y']
],
12
);
@ -70,17 +70,20 @@ function sierpinski2(num_defects) { @@ -70,17 +70,20 @@ function sierpinski2(num_defects) {
project.clear();
if(typeof num_defects == 'undefined') { num_defects = 0 };
var r = generate(
'IA'.split(''),
'IA',
[
['A'.split(''), 'B-A-B'.split('')],
['B'.split(''), 'A+B+A'.split('')]
['A', 'B-A-B'],
['B', 'A+B+A']
],
8
);
for(var i=0; i<num_defects; i++) {
r[Math.floor(Math.random()*r.length)] = '*';
}
if(num_defects > 0) {
r = r.split('');
for(var i=0; i<num_defects; i++) {
r[Math.floor(Math.random()*r.length)] = '*';
}
}
var actions = {
'A': draw_forward(),
@ -104,10 +107,10 @@ function sierpinski2(num_defects) { @@ -104,10 +107,10 @@ function sierpinski2(num_defects) {
function sierpinski() {
project.clear();
var r = generate(
'IF-G-G'.split(''),
'IF-G-G',
[
['F'.split(''), 'F-G+F+G-F'.split('')],
['G'.split(''), 'GG'.split('')]
['F', 'F-G+F+G-F'],
['G', 'GG']
],
6
);
@ -137,10 +140,10 @@ function sierpinski() { @@ -137,10 +140,10 @@ function sierpinski() {
project.clear();
if(typeof num_defects == 'undefined') { num_defects = 0 };
var r = generate(
'iIXF'.split(''),
'iIXF',
[
['X'.split(''), 'F+[[X]-X]-F[-FX]+X'.split('')],
['F'.split(''), 'FF'.split('')]
['X', 'F+[[X]-X]-F[-FX]+X'],
['F', 'FF']
],
6
);
@ -190,9 +193,9 @@ function sierpinski() { @@ -190,9 +193,9 @@ function sierpinski() {
project.clear();
if(typeof num_defects == 'undefined') { num_defects = 0 };
var r = generate(
'iIjJX'.split(''),
'iIjJX',
[
['X'.split(''), 'F[-lfX][cfX][+rfX]'.split('')],
['X', 'F[-lfX][cfX][+rfX]'],
//['F'.split(''), 'FF'.split('')],
//['L'.split(''), 'LL'.split('')],
//['C'.split(''), 'CC'.split('')],

4
lindenmayer-system/lindenmeyer-system.js

@ -28,13 +28,13 @@ function generate(start, rules, iterations) { @@ -28,13 +28,13 @@ function generate(start, rules, iterations) {
} else {
ruleres = rule[1];
}
newword.push(...ruleres);
newword += ruleres;
for(let i=0; i<ruleres.length; i++) {
newconsumed.push(true);
}
pos += rule[0].length;
} else {
newword.push(word[pos]);
newword += word[pos];
newconsumed.push(false);
pos += 1;
}

Loading…
Cancel
Save