xxxxxxxxxx
27
let turtle,
editor,
script,
tokens;
function setup() {
createCanvas(400, 400);
angleMode(DEGREES);
turtle = new Turtle(width / 2, height / 2, 0);
editor = select("#script");
editor.input(goTurtle);
strokeWeight(2);
stroke(233);
}
function goTurtle() {
resetMatrix();
turtle.reset();
script = editor.value();
tokens = script.trim().split(/\s/);
background(22);
for (let i = 0; i < tokens.length; i++) {
if (commands[tokens[i]] && tokens[i + 1]) {
i += commands[tokens[i]](tokens[i + 1]);
}
}
}