Browse Source

add length noise

master
Fr3deric 5 years ago
parent
commit
8a574d7462
  1. 3
      lindenmayer-system/lindenmeyer-system.html
  2. 17
      lindenmayer-system/lindenmeyer-system.js

3
lindenmayer-system/lindenmeyer-system.html

@ -190,7 +190,7 @@ function sierpinski() {
project.clear(); project.clear();
if(typeof num_defects == 'undefined') { num_defects = 0 }; if(typeof num_defects == 'undefined') { num_defects = 0 };
var r = generate( var r = generate(
'iIjX'.split(''), 'iIjJX'.split(''),
[ [
['X'.split(''), 'F[-lfX][cfX][+rfX]'.split('')], ['X'.split(''), 'F[-lfX][cfX][+rfX]'.split('')],
//['F'.split(''), 'FF'.split('')], //['F'.split(''), 'FF'.split('')],
@ -231,6 +231,7 @@ function sierpinski() {
'i': draw_set_dir(Math.PI), 'i': draw_set_dir(Math.PI),
'I': draw_angle_init(25/180 * Math.PI), 'I': draw_angle_init(25/180 * Math.PI),
'j': draw_set_turn_noise(1), 'j': draw_set_turn_noise(1),
'J': draw_set_length_noise(1),
'*': draw_angle_add((Math.random() - 0.5) * 0.01), '*': draw_angle_add((Math.random() - 0.5) * 0.01),
'-': draw_angle_turn(-1), '-': draw_angle_turn(-1),

17
lindenmayer-system/lindenmeyer-system.js

@ -51,6 +51,7 @@ function draw_initstate(p, state) {
if(!('dir' in state)) { if(!('dir' in state)) {
state.dir = 0; state.dir = 0;
state.turnnoise = 0; state.turnnoise = 0;
state.lennoise = 0;
} }
if(!('stepsize' in state)) { if(!('stepsize' in state)) {
state.stepsize = 1; state.stepsize = 1;
@ -76,6 +77,13 @@ function draw_set_turn_noise(level) {
} }
function draw_set_length_noise(level) {
return function(p, state) {
state.lennoise = level;
}
}
function draw_forward(factor=1) { function draw_forward(factor=1) {
return function(p, state) { return function(p, state) {
draw_initstate(p, state); draw_initstate(p, state);
@ -84,10 +92,11 @@ function draw_forward(factor=1) {
console.log('---------------------------'); console.log('---------------------------');
} }
var lastp = state.curpath.segments[state.curpath.segments.length - 1].point; var lastp = state.curpath.segments[state.curpath.segments.length - 1].point;
state.curpath.add(lastp.add( var noise = 1 + (Math.random() - 0.5) * state.lennoise;
new paper.Point(Math.sin(state.dir) * state.stepsize * factor, state.curpath.add(lastp.add(new paper.Point(
Math.cos(state.dir) * state.stepsize * factor) Math.sin(state.dir) * state.stepsize * factor * noise,
)); Math.cos(state.dir) * state.stepsize * factor * noise
)));
} }
} }

Loading…
Cancel
Save