Log in to post a comment.

// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(1);

// Global code will be evaluated once.
const turtle = new Turtle();

turtle.penup();
turtle.goto(0,0);
turtle.pendown();

x=.0
y=.0
z=.0
u=.0
v=.0
scale=50

const rotatex=50; // min=0, max=360, step=1
const rotatey=50; // min=0, max=360, step=1
const rotatez=50; // min=0, max=360, step=1

// The walk function will be called until it returns false.
function walk() 
{
    for(u=0;u<=4*3.14;u=u+0.02)
    {
        for(v=0.001;v<=1;v=v+0.02)
        {
            x=(v*Math.cos(u)-0.5*v*v*Math.cos(2*u))*scale
            y=(-v*Math.sin(u)-0.5*v*v*Math.sin(2*u))*scale
            z=4*v*Math.pow(1.5,Math.log(v))*Math.cos(3*u/2)/3*scale
            
            
            // Rotation in x
            xn=x
            yn=y*Math.cos(rotatex/360*2*3.1415)-z*Math.sin(rotatex/360*2*3.1415)
            zn=y*Math.sin(rotatex/360*2*3.1415)+z*Math.cos(rotatex/360*2*3.1415)

            x=xn
            y=yn
            z=zn

            // Rotation in y
            xn=x*Math.cos(rotatey/360*2*3.1415)+z*Math.sin(rotatey/360*2*3.1415)
            yn=y
            zn=-x*Math.sin(rotatey/360*2*3.1415)+z*Math.cos(rotatey/360*2*3.1415)

            x=xn
            y=yn
            z=zn

            // Rotation in y
            xn=x*Math.cos(rotatez/360*2*3.1415)-y*Math.sin(rotatez/360*2*3.1415)
            yn=x*Math.sin(rotatez/360*2*3.1415)+y*Math.cos(rotatez/360*2*3.1415)
            zn=z

            // convert to isometric view, orthographic
            // x' = (x - z) * cos(θ)
            // y' = y + (x + z) * sin(θ)
            // θ = 30° for isometric
            xiso=(xn-zn)*Math.cos(3.1415/6)
            yiso=yn+(xn+zn)*Math.sin(3.1415/6)
            turtle.goto(xiso,yiso);
        }
    }
    return false
}