Rotating shapes

A study in rotating shapes.

Log in to post a comment.

Canvas.setpenopacity(.75);

const min_radius = 2;
const radius_step = 1;
const steps = 30;
const rotate_per_step = .025;
const elems_side = 3;

const turtle = new Turtle();
turtle.radians();   
    
function walk(i) {
    for (let x=0; x<elems_side; x++) {
        for (let y=0; y<elems_side; y++) {
            draw_poly( (x/elems_side-.5*(1-1/elems_side))*200, (y/elems_side-.5*(1-1/elems_side))*200, turtle, 
                    3 + x + y*elems_side, // number of corners
                    i*radius_step+min_radius, // radius
                    (steps-i-1) * rotate_per_step * (1+y), // angle
                );    
        }
    }
    return i < steps-1;
}


function draw_poly(x,y,t, c, r, a) {
    const side = 2*Math.sin(Math.PI/c) * r;
    
    t.penup();
    t.goto(x,y);
    t.setheading(a);
    t.forward(r);
    t.setheading(a+Math.PI/2);
    t.pendown();
    
    t.right(Math.PI/c);
    for (let i=0; i<c; i++) {
        t.forward(side);
        t.right(Math.PI*2/c);
    }
}