Skip to content

Instantly share code, notes, and snippets.

@volfegan
Last active September 22, 2021 05:32
Show Gist options
  • Save volfegan/d24d93390e484ac99d81e81e8bd69ba7 to your computer and use it in GitHub Desktop.
Save volfegan/d24d93390e484ac99d81e81e8bd69ba7 to your computer and use it in GitHub Desktop.
Infinite Heart curve loop
//http://mathworld.wolfram.com/HeartCurve.html
float a=0; //angle
float x, y;
float scaleDiv = 40; //scale divisor for the size of the heart
void setup() {
size(720, 720);
colorMode(HSB, 360);
background(0);
noStroke();
}
void draw() {
//some gray lines on background
stroke(100, 10);
for (int i = 20; i < width; i += 20) {
if (random(1)> 0.7) continue;
line(0, i, width, i);
}
translate(width/2, height/2);
a++;
x=16*pow(sin(radians(a)), 3) * width/scaleDiv;
y=-1*(13*cos(radians(a))-5*cos(radians(2*a))-2*cos(radians(3*a))-cos(radians(4*a))) * width/scaleDiv;
float colour = (a+x/2+y/2)%360;
fill(colour, 360, 360);
circle(x, y, 15);
translate(-width/2, -height/2);
copy(this.get(), 0, 0, width, width, 1, 1, width-2, width-2); //Thanks @Hau_Kun for this trick
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment