/*My square is mad because the mouse stole his blocks. When you drag the mouse he gets big and angry
and then chases after the mouse. The faster you drag the mouse the bigger the square makes himself.
The mouse can trap the square when you click on him. He tires to move away but ultimately stays
guarded by the mouse until you drag the mouse again.
*/
float x = 50.0;
float y = 50.0;
float easing = 0.05;
float speed = 0.0;
float targetX, targetY, dragX, dragY;
void setup() {
size(400, 400);
fill(102);
smooth();
noStroke();
}
void draw() {
targetX = mouseX;
targetY = mouseY;
background(0);
x+= (targetX-x)* easing;
y+= (targetY-y)* easing;
fill(102);
float speed = dist(mouseX, mouseY, pmouseX, pmouseY);
rectMode(CENTER);
rect(x, y, 50+speed, 50+speed);
}
void mouseMoved() {
rect(x, y, 50+2*speed, 50+2*speed);
}
void mouseDragged() {
rectMode(CENTER);
rect(dragX, dragY, 200, 200);
}
void mousePressed() {
x+=(random(-20, 20));
y+=(random(-20, 40));
}
Beth - H
on Tuesday, Oct 21, 2008 – 8:23 pm