// Forked from "Fork: Phyllotactic Spiral" by rupertxrussell
// https://turtletoy.net/turtle/9794ca3a64

// Forked from "Phyllotactic Spiral" by Samolevsky
// https://turtletoy.net/turtle/176d80f96a

// Phyllotactic Spiral in TurtleToy

Canvas.setpenopacity(1);
const turtle = new Turtle();

// Constants
const rotation = 315.2;// min=1, max=360, step=0.05 // Angle in degrees
const mediumRotation = -0.322; //min=-1, max=1, step=0.001;
const fineRotation = 0.1263; //min=0, max=0.5, step=0.0001;
const scale = 3.26; // min=0.01, max=20, step=0.01 // Scaling factor for distance from center
const totalPoints = 588; // min=0.01, max=1000, step=1 // Total number of points in the spiral
const nudge = 0.40; // min=-2, max=2, step=0.1 

// Draw the Phyllotactic Spiral
for (let i = 0; i < totalPoints; i++) {
    const angle = i * (rotation + mediumRotation +  fineRotation);
    const radius = scale * Math.sqrt(i);
    const x = radius * Math.sin(angle * Math.PI / 180 + nudge);
    const y = radius * Math.cos(angle * Math.PI ) * Math.cos(angle * Math.PI / 180 + nudge);

    if (i === 0) {
        turtle.jump(x, y);
    } else {
        turtle.goto(x, y);
    }
}

function loop() {
    return false;
}