git @ Cat's Eye Technologies Erratic-Turtle-Graphics / 25afa8a
Option always runs a program. Chris Pressey 2 years ago
1 changed file(s) with 18 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
99 config.container.appendChild(can);
1010
1111 var turtle = (new ErraticTurtle()).init({ canvas: can });
12 turtle.reset();
13 var method = 'drawLines';
14 turtle[method]();
12 var program = "setxyp 0.125 0.5 lt 90 repeat 7 [ repeat 50 [ fd 150 lt 180 ] shiftxyp 0.125 0.0 ]";
13
14 function run() {
15 turtle.reset();
16 var p = (new Parser()).init(program);
17 var i = p.parseInstrs();
18 console.log(uneval(i));
19 interpretInstrs(i, turtle);
20 }
21
22 run();
1523
1624 var controlPanel = div(
1725 div(
2028 options: [
2129 {
2230 text: 'Lines',
23 value: 'drawLines',
31 value: "setxyp 0.125 0.5 lt 90 repeat 7 [ repeat 50 [ fd 150 lt 180 ] shiftxyp 0.125 0.0 ]"
2432 },
2533 {
2634 text: 'Boxes',
27 value: 'drawBoxes',
35 value: "setxyp 0.125 0.666 lt 90 repeat 7 [ repeat 400 [ fd 50 lt 90 ] shiftxyp 0.125 0.0 ]"
2836 },
2937 {
3038 text: 'Circles',
31 value: 'drawCircles',
39 value: "setxyp 0.125 0.666 lt 90 repeat 7 [ repeat 4500 [ fd 1.0 lt 4 ] shiftxyp 0.125 0.0 ]"
3240 },
3341 {
3442 text: 'Circle Chain',
35 value: 'drawCircleChain',
36 },
37 {
38 text: 'Logo',
39 value: 'logo',
40 program: "setxyp 0.125 0.5 lt 90 repeat 7 [ repeat 50 [ fd 150 lt 180 ] shiftxyp 0.125 0.0 ]"
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 ]"
4144 }
4245 ],
4346 onchange: function(option) {
44 method = option.value;
45 turtle.reset();
46 if (method === 'logo') {
47 var p = (new Parser()).init(option.program);
48 var i = p.parseInstrs();
49 console.log(uneval(i));
50 interpretInstrs(i, turtle);
51 } else {
52 turtle[method]();
53 }
47 program = option.value;
48 run();
5449 }
5550 })
5651 ),
5752 div(
58 button("Re-roll", { onclick: function() { turtle.reset(); turtle[method](); }})
53 button("Re-roll", { onclick: function() { run(); }})
5954 )
6055 );
6156 config.container.appendChild(controlPanel);