git @ Cat's Eye Technologies Erratic-Turtle-Graphics / f1047dd
These are interesting forms, but they're not replicating previous. Chris Pressey 2 years ago
3 changed file(s) with 34 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
99 config.container.appendChild(can);
1010
1111 var turtle = (new ErraticTurtle()).init({ canvas: can });
12 var program = "setxyp 0.125 0.5 lt 90 repeat 7 [ repeat 50 [ fd 150 lt 180 ] shiftxyp 0.125 0.0 ]";
12 var program = "seterr 0 0 setxyp 0.125 0.5 lt 90 repeat 7 [ repeat 50 [ fd 150 lt 180 ] shiftxyp 0.125 0.0 shifterr 0.01 2.0 ]";
1313
1414 function run() {
1515 turtle.reset();
2828 options: [
2929 {
3030 text: 'Lines',
31 value: "setxyp 0.125 0.5 lt 90 repeat 7 [ repeat 50 [ fd 150 lt 180 ] shiftxyp 0.125 0.0 ]"
31 value: "seterr 0 0 setxyp 0.125 0.5 lt 90 repeat 7 [ repeat 50 [ fd 150 lt 180 ] shiftxyp 0.125 0.0 shifterr 0.01 2.0 ]"
3232 },
3333 {
3434 text: 'Boxes',
35 value: "setxyp 0.125 0.666 lt 90 repeat 7 [ repeat 400 [ fd 50 lt 90 ] shiftxyp 0.125 0.0 ]"
35 value: "seterr 0 0 setxyp 0.125 0.666 lt 90 repeat 7 [ repeat 400 [ fd 50 lt 90 ] shiftxyp 0.125 0.0 shifterr 0.01 2.0 ]"
3636 },
3737 {
3838 text: 'Circles',
39 value: "setxyp 0.125 0.666 lt 90 repeat 7 [ repeat 4500 [ fd 1.0 lt 4 ] shiftxyp 0.125 0.0 ]"
39 value: "seterr 0 0 setxyp 0.125 0.666 lt 90 repeat 7 [ repeat 4500 [ fd 1.0 lt 4 ] shiftxyp 0.125 0.0 shifterr 0.025 0.333 ]"
4040 },
4141 {
4242 text: 'Circle Chain',
43 value: "setxyp 1.0 0.5 lt 90 repeat 7 [ repeat 1845 [ fd 2.0 lt 4 ] lt 180 ] repeat 7 [ repeat 1845 [ fd 2.0 lt 4 ] lt 180 ]"
43 value: "seterr 0 0 setxyp 1.0 0.5 lt 90 repeat 7 [ repeat 1845 [ fd 2.0 lt 4 ] lt 180 shifterr 0.025 1.5 ] repeat 7 [ repeat 1845 [ fd 2.0 lt 4 ] lt 180 shifterr -0.025 -1.5 ]"
4444 }
4545 ],
4646 onchange: function(option) {
114114 /*
115115 * Instr ::= "fd" Number | "rt" Number | "lt" Number
116116 * | "setxyp" Number Number | "shiftxyp" Number Number
117 * | "seterr" Number Number | "shifterr" Number Number
117118 * | "repeat" Number "[" Instrs "]".
118119 */
119120 this.parseInstr = function() {
141142 var yval = this.scanner.token;
142143 this.scanner.expectType('number');
143144 return ["shiftxyp", parseFloat(xval), parseFloat(yval)];
145 } else if (this.scanner.consume('seterr')) {
146 var rerrval = this.scanner.token;
147 this.scanner.expectType('number');
148 var merrval = this.scanner.token;
149 this.scanner.expectType('number');
150 return ["seterr", parseFloat(rerrval), parseFloat(merrval)];
151 } else if (this.scanner.consume('shifterr')) {
152 var rerrval = this.scanner.token;
153 this.scanner.expectType('number');
154 var merrval = this.scanner.token;
155 this.scanner.expectType('number');
156 return ["shifterr", parseFloat(rerrval), parseFloat(merrval)];
144157 } else if (this.scanner.consume('repeat')) {
145158 var val = this.scanner.token;
146159 this.scanner.expectType('number');
184197 case "shiftxyp":
185198 turtle.shiftXYProportional(instr[1], instr[2]);
186199 break;
200 case "seterr":
201 turtle.setErrorRates(instr[1], instr[2]);
202 break;
203 case "shifterr":
204 turtle.shiftErrorRates(instr[1], instr[2]);
205 break;
187206 case "repeat":
188207 for (var k = 0; k < instr[1]; k++) {
189208 interpretInstrs(instr[2], turtle);
4040 this.shiftXYProportional = function(dxp, dyp) {
4141 this.x += this.canvas.width * dxp;
4242 this.y += this.canvas.height * dyp;
43 };
44
45 this.setErrorRates = function(rerr, merr) {
46 this.rotateError = rerr;
47 this.moveError = merr;
48 };
49
50 this.shiftErrorRates = function(drerr, dmerr) {
51 this.rotateError += drerr;
52 this.moveError += dmerr;
4353 };
4454
4555 /* dtheta is in radians */