Hi all coders out there, i have drawn a heart shape using points and it is working , for drawing multiple hearts i have made a object “heart” with a constructor of passing 3 variable (size,x position and y position ) and two functions for drawing and beating but when i am drawing single heart its working but when trying to draw multiple heart only it displays the last heart drawn.
so please guys please help.
thank and regards
Abu Yazid.
code
/*heart h1=new heart(2,200,300);
heart h2=new heart(2,100,600);*/
heart h3=new heart(3, 700, 550);
//heart h4=new heart(5,500,550);
void setup()
{
fullScreen(P2D);
frameRate(60);
background(0);
}
void draw()
{
background(0);
/*h1.drawHeart();
h1.beat();
h2.drawHeart();
h2.beat();*/
h3.drawHeart();
h3.beat();
}
float HeartSize,x,y;
float orgSize;
class heart
{
heart(float hSize,float xPos, float yPos)
{
HeartSize=hSize;
orgSize=hSize;
x=xPos;
y=yPos;
}
void drawHeart()
{
stroke(250,0,0);
strokeWeight(2);
for(float t=0;t<=2*PI;t+=.01)
point((-16*HeartSize*pow(sin(t),3))+x,(-(13*HeartSize*cos(t)-5*HeartSize*cos(2*t)-2*HeartSize*cos(3*t)-cos(4*t)))+y);
}
void beat()
{
delay(30);
HeartSize+=.1;
if(HeartSize>=orgSize+1)
HeartSize=orgSize;
}
}