Home sweet home 🐝🐝🐝

Zooming rotating hexagons, inspired by Rene's turtletoy.net/turtle/92f5c871d5

Log in to post a comment.

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

const edge = 11; //min=2, max=50, step=1
const rotation = 111; //min=0, max=360, step = 1

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

let yInc = .8660254037844386 * edge; //Math.sin(60*Math.PI/180)*r;
let y = -100 * root2;    
let rotationAngle = rotation * Math.PI / 180;

// The walk function will be called until it returns false.
function walk(i) {
    let x = (-100 - (1.5*edge)) * root2;
    turtle.jump(((x + (i % 2 == 0? 0: 1.5*edge)) * Math.cos(rotationAngle)) - (y * Math.sin(rotationAngle)), ((x + (i % 2 == 0? 0: 1.5*edge)) * Math.sin(rotationAngle)) + (y * Math.cos(rotationAngle)));
    turtle.setheading((60 + rotation) % 360);
    while(x < 100 * root2) {
        for(let l = 0; l < 4; l++) {
            l == 3? turtle.penup(): turtle.pendown();
            turtle.forward(edge);
            turtle.left(l<2?60:-60);
        }
        x+=edge*3;
    }
    y += yInc;
    return y < 100 * root2;
}