|
|
|
@ -52,6 +52,10 @@ function generate(start, rules, iterations) {
@@ -52,6 +52,10 @@ function generate(start, rules, iterations) {
|
|
|
|
|
function draw_initstate(p, state) { |
|
|
|
|
if(!('dir' in state)) { |
|
|
|
|
state.dir = 0; |
|
|
|
|
state.turnnoise = 0; |
|
|
|
|
} |
|
|
|
|
if(!('stepsize' in state)) { |
|
|
|
|
state.stepsize = 1; |
|
|
|
|
} |
|
|
|
|
if(!('curpath' in state)) { |
|
|
|
|
p.addChild(new paper.Path()); |
|
|
|
@ -67,7 +71,14 @@ function draw_set_dir(dir) {
@@ -67,7 +71,14 @@ function draw_set_dir(dir) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function draw_forward() { |
|
|
|
|
function draw_set_turn_noise(level) { |
|
|
|
|
return function(p, state) { |
|
|
|
|
state.turnnoise = level; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function draw_forward(factor=1) { |
|
|
|
|
return function(p, state) { |
|
|
|
|
draw_initstate(p, state); |
|
|
|
|
if(state.curpath.segments.length == 0) { |
|
|
|
@ -76,12 +87,26 @@ function draw_forward() {
@@ -76,12 +87,26 @@ function draw_forward() {
|
|
|
|
|
} |
|
|
|
|
var lastp = state.curpath.segments[state.curpath.segments.length - 1].point; |
|
|
|
|
state.curpath.add(lastp.add( |
|
|
|
|
new paper.Point(Math.sin(state.dir), Math.cos(state.dir)) |
|
|
|
|
new paper.Point(Math.sin(state.dir) * state.stepsize * factor, |
|
|
|
|
Math.cos(state.dir) * state.stepsize * factor) |
|
|
|
|
)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function draw_stepsize_mul(factor) { |
|
|
|
|
return function(p, state) { |
|
|
|
|
if(typeof factor == 'function') { |
|
|
|
|
var f = factor(); |
|
|
|
|
} else { |
|
|
|
|
var f = factor; |
|
|
|
|
} |
|
|
|
|
draw_initstate(p, state); |
|
|
|
|
state.stepsize *= f; |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function draw_turn(angle) { |
|
|
|
|
return function(p, state) { |
|
|
|
|
draw_initstate(p, state); |
|
|
|
@ -93,7 +118,8 @@ function draw_turn(angle) {
@@ -93,7 +118,8 @@ function draw_turn(angle) {
|
|
|
|
|
function draw_angle_turn(fac) { |
|
|
|
|
return function(p, state) { |
|
|
|
|
draw_initstate(p, state); |
|
|
|
|
state.dir += state.angle * fac; |
|
|
|
|
var a = state.angle * (1 + (Math.random() - 0.5) * state.turnnoise); |
|
|
|
|
state.dir += a * fac; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -120,6 +146,7 @@ function draw_state_push() {
@@ -120,6 +146,7 @@ function draw_state_push() {
|
|
|
|
|
state.stack.push({ |
|
|
|
|
pos: state.curpath.segments[state.curpath.segments.length - 1].point, |
|
|
|
|
dir: state.dir, |
|
|
|
|
stepsize: state.stepsize, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -129,6 +156,7 @@ function draw_state_pop() {
@@ -129,6 +156,7 @@ function draw_state_pop() {
|
|
|
|
|
return function(p, state) { |
|
|
|
|
var s = state.stack.pop(); |
|
|
|
|
state.dir = s.dir; |
|
|
|
|
state.stepsize = s.stepsize; |
|
|
|
|
p.addChild(new paper.Path()); |
|
|
|
|
state.curpath = p.lastChild; |
|
|
|
|
state.curpath.add(s.pos); |
|
|
|
|