//Keep the cursor from the monster unless you want him to eat it!
BlinkingEye eye1;
boolean eaten = false;
int eat = 0;
float D;
float mAng;
float timeEaten;
PImage cursor;
void setup() {
size(600, 400);
frameRate(30);
smooth();
background(255);
cursor = loadImage( "cursor.png");
noCursor();
eye1 = new BlinkingEye(width/2, height/2);
} // end void setup
void draw() {
background(255);
noStroke();
if (eaten == false) {
eye1.update(mouseX,mouseY);
}
else {
eye1.update(random(width), random(height));
}
//eat the cursor
//println(get(mouseX, mouseY));
if (get(mouseX, mouseY) != -1) {
eaten = true;
timeEaten = millis();
fill(255);
fill(100);
}
else if (eaten == false){
fill(255);
ellipse(mouseX, mouseY, 30, 30);
image(cursor, mouseX, mouseY);
}
else if ((eaten == true) && (millis()- timeEaten) > 5000) {
eaten = false;
}
eye1.draw();
} // end void draw;
class BlinkingEye
{
float x,y;
float px,py;
int age;
float mx,my;
float _mx, _my;
BodyPart parts[];
int num_of_BodyPart = 30;
BlinkingEye(float _x, float _y)
{
x = _x;
y = _y;
px = x;
py = y;
age = 0;
parts = new BodyPart[num_of_BodyPart];
for(int i=0;i<parts.length;i++){
parts[i] = new BodyPart(width/2, height/2, num_of_BodyPart-i + 10, 0);
}
}
void update(float _x, float _y)
{
px = x;
py = y;
x += (_x - x)*0.1;
y += (_y - y)*0.1;
age++;
//draw();
for(int i=0;i<num_of_BodyPart;i++){
if(i == 0){
parts[i].update(eye1.x,eye1.y);
}
else
{
parts[i].update(parts[i-1].x,parts[i-1].y);
}
parts[i].draw();
}
}
void draw()
{
pushMatrix();
translate(x,y);
popMatrix();
}
}
class BodyPart
{
float x,y;
float radius;
BodyPart(float _x, float _y, float _radius, float _ang)
{
x = _x;
y = _y;
radius = _radius;
}
void update(float _x, float _y){
if(dist(x,y,_x,_y)> 5)
{
float d = dist(x,y,_x,_y);
float angle = atan2((y-_y),(x-_x));
x = _x + cos(angle) * 5;
y = _y + sin(angle) * 5;
}
else
{
float d = dist(x,y,_x,_y);
float angle = atan2((y-_y),(x-_x));
x = _x + cos(angle) * d;
y = _y + sin(angle) * d;
}
//draw();
}
void draw()
{
fill(0);
ellipse(x,y,radius,radius);
}
}
Tiffany - L
on Monday, Nov 24, 2008 – 12:11 pm