Triangle Spiral

Simple Triangle

Log in to post a comment.

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

Canvas.setpenopacity(.75);

const min_radius = 0;
const radius_step = 0.5;
const steps = 30;
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, 3, 60, 0);
    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);
    }
}