Circle to Square ⚪️⬜️

Once again a reaction to a turtle by markknol: Square to Circle ⬜️⚪️

Log in to post a comment.

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

// Global code will be evaluated once.
const turtle = new Turtle();

const radius = 90;
const side = 90;
const distortion = 2;

// The walk function will be called until it returns false.
function walk(i) {
    let t = Math.random() * Math.PI * 2;
    let x = Math.sin(t) * radius;
    let y = Math.cos(t) * radius;
    
    x += (Math.sin(Math.random() * Math.PI * 2) * distortion);
    y += (Math.cos(Math.random() * Math.PI * 2) * distortion);
    
    let xM = side / 2;
    let yM = side / 2;
    switch(Math.round(Math.random())) {
        case 0:
            xM *= Math.random();
            break;
        case 1:
            yM *= Math.random();
            break;
    }
    
    xM *= (Math.round(Math.random()) * 2) - 1;
    yM *= (Math.round(Math.random()) * 2) - 1;
    
    turtle.jump(x, y);
    turtle.goto(xM, yM);
    return i < 1000;
}