Divisions IV

A new take on divisions.

Log in to post a comment.

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

const iterations = 4;       //min = 0, max = 8, step = 1
const size = 80;            //min = 10, max = 100, step = 1
const squaring = 0;              //min = 0, max = 1, step = 0.01

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

function divide(x, y, s, l){
    
    if(l == 0){
        const rand = Math.random();
        
        
        if(rand < 0.5){
            turtle.jump(x, y-s);
            turtle.seth(90);
            turtle.forward(squaring * s);
            turtle.circle((1-squaring)*s, 90);
            turtle.forward(squaring * s);

            turtle.jump(x, y+s);
            turtle.seth(-90);
            turtle.forward(squaring * s);
            turtle.circle((1-squaring)*s, 90);
            turtle.forward(squaring * s);
        } else {
            turtle.jump(x-s, y);
            turtle.seth(0);
            turtle.forward(squaring * s);
            turtle.circle((1-squaring)*s, 90);
            turtle.forward(squaring * s);

            turtle.jump(x+s, y);
            turtle.seth(180);
            turtle.forward(squaring * s);
            turtle.circle((1-squaring)*s, 90);
            turtle.forward(squaring * s);
        }
        
    } 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 until it returns false.
function walk(i) {
    
    return false;
}