Fork: Triangle Spiral

Simple Polygon Spiral

Log in to post a comment.

// Forked from "Triangle Spiral" by artuaragon
// https://turtletoy.net/turtle/09976593bf

// Forked from "Triangles" by zoso95
// https://turtletoy.net/turtle/88ef81ceeb

Canvas.setpenopacity(1);

const min_radius = 0;
const max_radius = 55;  //min=-37 max=100 step=1
const radius_step = 0.5;
const steps = 100; //min=1 max=100 step=1
const vert = 6; //min=2 max=6 step=1
const rotate_per_step = .025;
const elems_side = 5;

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,
    //         //         i*radius_step+min_radius, // radius
    //         //         (steps-i-1) * rotate_per_step * (1+y), // angle
    //         //     );    
    //         draw_poly(x/elems_side, y/elems_side, turtle, 3, 60, 0);
    //         draw_poly(x/elems_side, y/elems_side, turtle, elems_side, 60, 0);
    //     }
    // }
    
    draw_poly(0, 0, turtle, vert, max_radius-i, i);
    return i < steps-1;
}


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