canvas.clear(); // Zeichenfläche löschen var f = new Turtle(1); var t = new Turtle(1); var h = new Turtle(1); f.penColor(255,0,0); f.penWidth(5); t.penColor(0,255,0); t.penWidth(5); h.penColor(0,0,255); h.penWidth(5); var fCmdList = ["F30", "R90", "F20", "L180", "F20", "R90", "F30", "R90", "F30" ]; var tCmdList = [ "U", "R90", "F45", "L90", "D", "F60", "L180", "F20", "R90", "F10", "L180", "F20" ]; var hCmdList = [ "U", "R90", "F70", "L90", "D", "F60", "L180", "F30", "L90", "F25", "L90", "F30", "R180", "F60", "L90" ]; function move(t, command) { // command interpreter switch (command.charAt(0)) { case 'F' : t.forward(parseInt(command.substring(1))); break; case 'R' : t.right(parseInt(command.substring(1))); break; case 'L' : t.left(parseInt(command.substring(1))); break; case 'U' : t.penUp(); break; case 'D' : t.penDown(); break; }; }; for(var step = 0; step < 20; step++) { if (step < fCmdList.length) move(f, fCmdList[step]); if (step < tCmdList.length) move(t, tCmdList[step]); if (step < hCmdList.length) move(h, hCmdList[step]); } // now the turtles leave the stage f.penUp(); t.penUp(); h.penUp(); for(var i = 0 ; i < 30; i++) { h.forward(20); // leading t.setAngleTo(h); t.forward(20); f.setAngleTo(h); f.forward(20); }
ausführen