New turtle (with drunkness)

Just for fun

Log in to post a comment.

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

const drunkness = 0;        // min = 0, max = 20, step = 0.5
const radius = 50;


// Global code will be evaluated once.
const turtle = new Turtle();
turtle.penup();
turtle.goto(0,-radius);
turtle.pendown();

let angle = -Math.PI / 2;

// The walk function will be called until it returns false.
function walk(i) {
    
    let x = Math.cos(angle) * radius;
    let y = Math.sin(angle) * radius;
    
    let drunknessDirection = Math.random() * Math.PI * 2;
    let drunknessAmount = Math.random() * drunkness;
    
    x += Math.cos(drunknessDirection) * drunknessAmount;
    y += Math.sin(drunknessDirection) * drunknessAmount;
    
    turtle.goto(x, y);
    
    angle += Math.PI / 1.25;
    
    if( i < 49) return true;
    else{
        turtle.goto(0, -radius);
        return false;
    }
}