Heart Curve

An adaptation of the Heart Curve, while playing around with some parameters.
mathworld.wolfram.com/heartcurve.html

Log in to post a comment.

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

const turtle = new Turtle();
const PI_TWO = Math.PI * 2;

let heartSize = 0.45;//min=0.1, max=1.0, step=0.05

// The walk function will be called until it returns false.
function walk(i) {
    let s = i * heartSize;
    let o = i * 2 - 30;
    
    for(a = 0; a < PI_TWO; a += 0.01) {
       let b = (s * 12) * Math.cos(a);
       let c = (s * 5)  * Math.cos(a * 2);
       let d = (s * 2)  * Math.cos(a * 3);
       let e = (s * 1)  * Math.cos(a * 4);
       
       let x = (s * 17) * Math.pow(Math.sin(a), 3); 
       let y = -(b - c - d - e);
       
       draw_cross(x, y + o);
    }
    
    return i < 12;
}

function draw_cross(x, y) {
   turtle.penup();
    
   turtle.goto(x - 1, y - 1);
   turtle.pendown();
   turtle.goto(x + 1, y + 1);
   turtle.penup();
   
   turtle.goto(x + 1, y - 1,);
   turtle.pendown();
   turtle.goto(x - 1, y + 1);
   turtle.penup();
}