/* the idea for my square interaction is 'the rules of attraction.
With this idea that you always want what you can't have. So when you click, the square
is always opposite of you, yet when you just move the mouse, it follows you passively.
Finally, no matter what, when they touch, there is a little suprise.
*/
float x, y; //set location
float targetx, targety; //target locations for each setting
float easing = 0.1; //standard easing
float speed = 0.0;
float vibrate; // for erratic behavior
void setup () {
size(400, 400);
smooth();
noStroke();
}
void draw () {
background(0);
x += (targetx - x) * easing; //set easing spead for X and Y
y += (targety - y) * easing;
fill (152); //square color
if ( dist(mouseX, mouseY, x, y) < 30) { //if mouse contacts square, erratic behavior
vibrate = random(0,100);
rectMode(CENTER);
rect(x, y, vibrate, vibrate);
}
else { //else the square is constant
rectMode(CENTER);
rect(x, y, 30, 30);
}
}
void mouseMoved () { //square follows mouse slowly
targetx = mouseX;
targety = mouseY;
easing = 0.03;
}
void mouseDragged () { //they act as opposites
targetx = width - mouseX;
targety = height - mouseY;
easing = 0.9;
}
void mouseReleased () { //the square eases back to cursor
targetx = mouseX;
targety = mouseY;
easing = 0.05;
}
void mousePressed () {// they quickly seperate
targetx = width - mouseX;
targety = width - mouseY;
easing = 0.5;
}Everett - H
on Wednesday, Oct 22, 2008 – 2:02 am