//This shows the behavior of escaping
//The larger gray rect wants to escape from the small white rect
//but no matter how gray changes its size or value, white still sees it and follows it.
float x = 0;
float y = 0;
float easing = 0.1;
float maxDistance;
void setup() {
size(400, 400);
smooth();
noCursor();
maxDistance = dist(0, 0, width, height);
}
void draw() {
background(0);
//magnification away from center
float d = dist(width/2, height/2, mouseX, mouseY);
//easing effect
float targetX = mouseX;
float targetY = mouseY;
x += (targetX - x) * easing;
y += (targetY - y) * easing;
//the small white rectangle that follows the gray rectangle
rect(mouseX, mouseY, d*0.5, d*0.5);
fill(255);
//the gray rectangle which the cursor controls
rect(x, y, 10, 10);
noStroke();
fill(200);
}
//gray rectangle becomes a darker rect and hide amoung the others
void mouseDragged() {
fill(50);
for ( int i = 0; i <= width; i +=50) {
for ( int j = 0; j <= height; j += 50) {
float mouseDist = dist(mouseX, mouseY, i, j);
float l = (mouseDist / maxDistance ) * 100;
rect(i, j, l, l);
}
}
}
Justin - H
on Tuesday, Oct 21, 2008 – 2:49 pm