TMHTtoy: 🐀🐢🐢 🐢🐢

Splinter teaches the Teenage Muntant Hero TurtleToys to draw()

Log in to post a comment.

// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(.5);

const distanceScalar = 1.2; // min=.5, max=10, step=0.1  
const deltaAngle = 1; // min=-45, max=45, step=1 

class Sensei {
    constructor(distanceScalar, deltaAngle) { this.distanceScalar = distanceScalar; this.angle = 90 + deltaAngle; }
    sense(i) { this.i = i; }
    command(turtle, plan) {
        this.angle *= -1;
        plan(turtle, this.i * this.distanceScalar, this.angle)
    }
}

// Global code will be evaluated once.
const Splinter = new Sensei(distanceScalar, deltaAngle);

const Raphael = new Turtle();
const Leonardo = new Turtle();
const Michelangelo = new Turtle();
const Donatello = new Turtle();
Michelangelo.right(45);
Donatello.right(45);

// The walk function will be called until it returns false.
function walk(i) {
    Splinter.sense(i);
    
    Splinter.command(Raphael, move);
    Splinter.command(Leonardo, move);
    Splinter.command(Michelangelo, move);
    Splinter.command(Donatello, move);
    
    return i < 1000;
}

function move(turtle, distance, angle) {
    turtle.forward(distance);
    turtle.right(angle);
}