The Face Class
class Face
{
int x;
int y;
int r;
int colour;
int eyeColour;
Face(int xx, int yy, int rr, int col, int eyeCol)
{
x = xx;
y = yy;
r = rr;
colour = col;
eyeColour = eyeCol;
}
Face()
{
x = width/2;
y = height/2;
r = width/10;
colour=#FF0000;
eyeColour=#00FF00;
}
void display()
{
stroke(colour);
fill(colour);
ellipse(x,y,r*2,r*2);
stroke(eyeColour);
fill(eyeColour);
ellipse(x - r + 2 * r / 4, y - r + 2 * r / 4, 2 * r / 6, 2 * r / 6);
ellipse(x - r + 6 * r / 4, y - r + 2 * r / 4, 2 * r / 6, 2 * r / 6);
}
boolean collide(Face f)
{
float centreSeparation = sqrt(pow(f.x - x,2) + pow(f.y - y,2));
if (centreSeparation - f.r - r < 0)
return true;
else
return false;
}
void move()
{
x++;
}
void grow()
{
r++;
}
void setLocation(int x, int y)
{
this.x = x;
this.y = y;
}
}
Face f;
Face f2 = new Face(500,400, 100, #FFFF00, 0);;
void setup()
{
size(600,600);
f = new Face();
f.setLocation(0, f.y);
}
void draw()
{
background(255);
f.move();
f.display();
f2.grow();
f2.display();
if (f.collide(f2))
{
noLoop();
println("BANG");
}
}