Divisions VIII

Squares that go circles.

Log in to post a comment.

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

const iterations = 5;       //min = 0, max = 8, step = 1
const size = 90;            //min = 10, max = 100, step = 1
const roundCorner = 40;      //min = 0, max = 100, step = 1


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

function divide(x, y, s, l){
    
    if(l == 0){
        const rand = Math.random();
        
        let size = s * rand;
        
        let r = roundCorner / 100;

        turtle.jump(x-(1-r)*size, y-size);
        turtle.seth(0);
        for(let i = 0; i < 4; i++){
            turtle.forward(2*(1-r)*size);
            turtle.circle(r*size, 90);
        }
    } else {
        l--;
        s /= 2;
        
        divide(x+s, y+s, s, l);
        divide(x+s, y-s, s, l);
        divide(x-s, y+s, s, l);
        divide(x-s, y-s, s, l);
    }
}

divide(0, 0, size, iterations)

// The walk function will be called once and do nothing
function walk(i) {
    
    return false;
}