Browse Source

let fern grow upward

master
Fr3deric 6 years ago
parent
commit
769b4e5845
  1. 7
      lindenmayer-system/lindenmeyer-system.html
  2. 9
      lindenmayer-system/lindenmeyer-system.js

7
lindenmayer-system/lindenmeyer-system.html

@ -136,7 +136,7 @@ function sierpinski() {
function barnsley_fern() { function barnsley_fern() {
project.clear(); project.clear();
var r = generate( var r = generate(
'IXF'.split(''), 'iIXF'.split(''),
[ [
['X'.split(''), 'F+[[X]-X]-F[-FX]+X'.split('')], ['X'.split(''), 'F+[[X]-X]-F[-FX]+X'.split('')],
['F'.split(''), 'FF'.split('')] ['F'.split(''), 'FF'.split('')]
@ -149,7 +149,8 @@ function sierpinski() {
r, r,
{ {
'F': draw_forward(), 'F': draw_forward(),
'I': draw_angle_init(25/180 * Math.PI), 'i': draw_set_dir(Math.PI),
'I': draw_angle_init(25/180 * Math.PI + Math.random() * 0.2),
'-': draw_angle_turn(-1), '-': draw_angle_turn(-1),
'+': draw_angle_turn(1), '+': draw_angle_turn(1),
'[': draw_state_push(), '[': draw_state_push(),
@ -157,7 +158,7 @@ function sierpinski() {
} }
); );
p.scale(2); p.scale(2);
p.translate(new Point(200, 200)); p.translate(new Point(200, 300));
p.strokeWidth = 1; p.strokeWidth = 1;
p.strokeColor = '#ff00ff'; p.strokeColor = '#ff00ff';
} }

9
lindenmayer-system/lindenmeyer-system.js

@ -45,7 +45,7 @@ function generate(start, rules, iterations) {
function draw_initstate(p, state) { function draw_initstate(p, state) {
if(!('dir' in state)) { if(!('dir' in state)) {
state.dir = 0;//Math.PI/2; state.dir = 0;
} }
if(!('curpath' in state)) { if(!('curpath' in state)) {
p.addChild(new paper.Path()); p.addChild(new paper.Path());
@ -54,6 +54,13 @@ function draw_initstate(p, state) {
} }
function draw_set_dir(dir) {
return function(p, state) {
state.dir = dir;
}
}
function draw_forward() { function draw_forward() {
return function(p, state) { return function(p, state) {
draw_initstate(p, state); draw_initstate(p, state);

Loading…
Cancel
Save