Butterfly curve variant

original curve with nz=0
paulbourke.net/geometry/butterfly/

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();

const nx=1; // min=-2, max=2, step=.1
const ny=1; // min=-2, max=2, step=.1
const nz=0; // min=-2, max=2, step=.1
const rotatex=107; // min=0, max=360, step=1
const rotatey=148; // min=0, max=360, step=1
const rotatez=50; // min=0, max=360, step=1
const scale=17; // min=0, max=100, step=1

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

// The walk function will be called until it returns false.
function walk() 
{
    for(u=0;u<=24*3.14;u=u+0.04)
    {
            x=nx*Math.cos(u)*(Math.pow(2.71828,Math.cos(u))-2*Math.cos(4*u)-Math.pow(Math.sin(u/12),5))*scale
            y=ny*Math.sin(u)*(Math.pow(2.71828,Math.cos(u))-2*Math.cos(4*u)-Math.pow(Math.sin(u/12),5))*scale

            z=nz*Math.sin(u)*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
}