|
|
|
@ -43,25 +43,26 @@ function generate(start, rules, iterations) {
@@ -43,25 +43,26 @@ function generate(start, rules, iterations) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function draw_initstate(state) { |
|
|
|
|
function draw_initstate(p, state) { |
|
|
|
|
if(!('dir' in state)) { |
|
|
|
|
state.dir = 0;//Math.PI/2;
|
|
|
|
|
} |
|
|
|
|
if(!('curpath' in state)) { |
|
|
|
|
p.addChild(new paper.Path()); |
|
|
|
|
state.curpath = p.lastChild; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function draw_forward() { |
|
|
|
|
return function(p, state) { |
|
|
|
|
draw_initstate(state); |
|
|
|
|
if(p.children.length == 0) { |
|
|
|
|
p.addChild(new paper.Path()); |
|
|
|
|
} |
|
|
|
|
var pp = p.lastChild; |
|
|
|
|
if(pp.length == 0) { |
|
|
|
|
pp.add(new paper.Point(0, 0)); |
|
|
|
|
draw_initstate(p, state); |
|
|
|
|
if(state.curpath.segments.length == 0) { |
|
|
|
|
state.curpath.add(new paper.Point(0, 0)); |
|
|
|
|
console.log('---------------------------'); |
|
|
|
|
} |
|
|
|
|
var lastp = pp.segments[pp.segments.length - 1].point; |
|
|
|
|
pp.add(lastp.add( |
|
|
|
|
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)) |
|
|
|
|
)); |
|
|
|
|
} |
|
|
|
@ -70,7 +71,7 @@ function draw_forward() {
@@ -70,7 +71,7 @@ function draw_forward() {
|
|
|
|
|
|
|
|
|
|
function draw_turn(angle) { |
|
|
|
|
return function(p, state) { |
|
|
|
|
draw_initstate(state); |
|
|
|
|
draw_initstate(p, state); |
|
|
|
|
state.dir += angle; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -78,7 +79,7 @@ function draw_turn(angle) {
@@ -78,7 +79,7 @@ function draw_turn(angle) {
|
|
|
|
|
|
|
|
|
|
function draw_angle_turn(fac) { |
|
|
|
|
return function(p, state) { |
|
|
|
|
draw_initstate(state); |
|
|
|
|
draw_initstate(p, state); |
|
|
|
|
state.dir += state.angle * fac; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -98,6 +99,30 @@ function draw_angle_add(delta) {
@@ -98,6 +99,30 @@ function draw_angle_add(delta) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function draw_state_push() { |
|
|
|
|
return function(p, state) { |
|
|
|
|
if(typeof state.stack == 'undefined') { |
|
|
|
|
state.stack = new Array(); |
|
|
|
|
} |
|
|
|
|
state.stack.push({ |
|
|
|
|
pos: state.curpath.segments[state.curpath.segments.length - 1].point, |
|
|
|
|
dir: state.dir, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function draw_state_pop() { |
|
|
|
|
return function(p, state) { |
|
|
|
|
var s = state.stack.pop(); |
|
|
|
|
state.dir = s.dir; |
|
|
|
|
p.addChild(new paper.Path()); |
|
|
|
|
state.curpath = p.lastChild; |
|
|
|
|
state.curpath.add(s.pos); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function draw(word, actions) { |
|
|
|
|
var p = new paper.CompoundPath(); |
|
|
|
|
var state = {}; |
|
|
|
|