// Welcome to Turtletoy!
//
// Turtletoy is a community for creative coding. We believe the joy 
// is in the craft. 
//
// ---------------------------------------------------------------
// A NOTE ON AI:
// Please do not publish code entirely generated by AI. 
// We want to see YOUR creativity, your mistakes, and your logic. 
// If you use AI to learn, try to rewrite the code yourself before 
// sharing, so others can learn from your human approach.
// ---------------------------------------------------------------
//
// API Reference: https://turtletoy.net/syntax
const scale = 18;//min=5,max=200,step=1
const density = 0.01;//min=0.005,max=1,step=0.005
const loops = 20;//min=5,max=1000,step=1
const a = 2;//min=0,max=50,step=1
const k = 4;//min=1,max=20,step=1
const p = 5;//min=1,max=20,step=1
const shift = 24;//min=5,max=100,step=1
const skew = 1;//min=0.1,max=10,step=0.1
Canvas.setpenopacity(1);

// Global code will be evaluated once.
const turtle = new Turtle();
turtle.penup();
turtle.goto(0,0);
turtle.pendown();

// The walk function will be called until it returns false.
function walk(i) {
    let t = i*density;
    let r = Math.exp(Math.sin(t)) - a*Math.cos(k*t) + Math.pow(Math.sin((2*t - Math.PI)/shift),p);
    let x = Math.cos(t)* r * scale;
    let y = -Math.sin(t) * r * scale * skew;
    turtle.goto(x,y);
    return t < loops * Math.PI;

}