/* L-System.js */ /* Author: Daniel Gray */ /* daniel@technigami.com */ addV = function(start, angle, length) { /* Adds a polar vector to the start position */ return [start[0] + Math.cos(angle)*length, start[1] + Math.sin(angle)*length]; } G_ = function(v,w,P) { /* L-System Interpreter */ ret = ""; for(ch in w) { if(v.indexOf(w[ch]) >= 0) { ret = ret.concat(P[w[ch]]); } else { ret = ret.concat(w[ch]); } } return ret; } G = function(v, w, P, levels) { /* L-System Iterator */ ret = w; for(i=0;i -1 ){ position = addV(position,angle,L); path = path + "L " + position[0] + " " + position[1]; } if(w[ch] === "+") { angle -= t_left; } if(w[ch] === "-") { angle += t_right; } if(w[ch] === "[") { angle += t_right; position_stack.push([position, angle]); } if(w[ch] === "]") { last_pos_ = position_stack.pop(); last_pos = last_pos_[0]; angle = last_pos_[1]; angle += t_left; path = path + " L " + last_pos[0] + " " + last_pos[1]; } } return path; }