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() { @@ -136,7 +136,7 @@ function sierpinski() {
function barnsley_fern() {
project.clear();
var r = generate(
'IXF'.split(''),
'iIXF'.split(''),
[
['X'.split(''), 'F+[[X]-X]-F[-FX]+X'.split('')],
['F'.split(''), 'FF'.split('')]
@ -149,7 +149,8 @@ function sierpinski() { @@ -149,7 +149,8 @@ function sierpinski() {
r,
{
'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_state_push(),
@ -157,7 +158,7 @@ function sierpinski() { @@ -157,7 +158,7 @@ function sierpinski() {
}
);
p.scale(2);
p.translate(new Point(200, 200));
p.translate(new Point(200, 300));
p.strokeWidth = 1;
p.strokeColor = '#ff00ff';
}

9
lindenmayer-system/lindenmeyer-system.js

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

Loading…
Cancel
Save