Divisions

Trying (well, copying) from another turtle.
this one : Tiling Lines

And adding circles too.

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 direction = 0;        //min = 0, max = 2, step = 1, (horizontal, diagonal, circles)

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

function divide(x, y, s, l){
    if(l == 0){
        if(direction == 0){
            if(Math.random() < 0.5){
                turtle.jump(x, y-s);
                turtle.goto(x, y+s);
            } else {
                turtle.jump(x-s, y);
                turtle.goto(x+s, y);
            }
        } else if(direction == 1){
            if(Math.random() < 0.5){
                turtle.jump(x+s, y-s);
                turtle.goto(x-s, y+s);
            } else {
                turtle.jump(x-s, y-s);
                turtle.goto(x+s, y+s);
            }
            
        } else if(direction == 2){
            let rand = Math.random();
            if(rand < 0.25){
                turtle.jump(x-s, y-s);
                turtle.seth(0);
                turtle.circle(2*s, 90);
            } else if(rand < 0.5){
                turtle.jump(x-s, y-s);
                turtle.seth(90);
                turtle.circle(-2*s, 90);
            } else if(rand < 0.75){
                turtle.jump(x+s, y-s);
                turtle.seth(-180);
                turtle.circle(-2*s, 90);
            } else {
                turtle.jump(x+s, y-s);
                turtle.seth(90);
                turtle.circle(2*s, 90);
            }
        }
    } else {
        s /= 2;
        l -= 1;
        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) {
    // nothing here.
    return i < 100;
}