// use mouse press to store original position of square
// use mouse drag to move squares to new position and change color
// mouse released fires square to original position
float x = 25;
float y = 25;
float easing = 0.1;
float targetX;
float targetY;
float speed =0.0;
float c=100;
float px;
float py;
void setup() {
size(400, 400);
smooth();
noStroke();
frameRate(60);
background(0);
}
void draw() {
background(0);
targetX = mouseX;
targetY = mouseY;
fill(c);
x += (targetX-x)*easing;
y += (targetY-y)*easing;
rect(x, y, 35, 35);
speed = dist(mouseX, mouseY, pmouseX, pmouseY);
}
void mousePressed() {
px = mouseX;
py = mouseY;
}
// square fires at previous
void mouseReleased() {
x=px;
y=py;
println(x);
println(y);
}
void mouseDragged() {
c += speed/2;
c = constrain(c, 0, 200);
if (c == 200) {
c = 100;
}
}Scott - H
on Wednesday, Oct 22, 2008 – 3:10 am