// The relationship between the mouse and the gray square
// is supposed to be an invisible rubber band--
// If you click and drag the mouse slowly, you can stretch it
// away from you. When you release the mouse, it snaps back.
float x;
float y;
float tx;
float ty;
float distance;
float d;
float easing = 0.09;
float rectSize = 50;
boolean snapped = false;
void setup () {
size(400, 400);
smooth();
fill(102);
noStroke();
x = width/2;
tx = x;
y = height/2;
ty = y;
}
void draw () {
background(0);
x += (tx-x) * easing;
y +=(ty-y) * easing;
rect(x, y, rectSize, rectSize);
if(snapped == true) {
rect(x, y, 50, 50);
}
}
void mouseMoved() {
tx =mouseX;
ty = mouseY;
rectSize= 50;
snapped = false;
}
void mouseDragged() {
tx = width - mouseX;
ty = height - mouseY;
easing = 0.03;
distance = dist(mouseX, mouseY, width-mouseX, height-mouseY);
println(2500/distance);
d = lerp (50, 15, distance/565);
rectSize = d;
}
void mouseReleased() {
tx = mouseX;
ty = mouseY;
distance = dist(tx, ty, width-mouseX, height-mouseY);
easing = distance / 1000;
rectSize = (50-d) * easing;
snapped = true;
}Tiffany - H
on Tuesday, Oct 21, 2008 – 6:03 pm
One Comment
the mouseRealeased function is very interesting