/* I volunteer at a breeding kennel for the Guiding Eyes for the Blind Charity
Group in my hometown. My job is to play with and socialize young pups so that
they are more receptive to training later on in the program, and hopefully become
Guide Dogs. In my experience, there is usually one pup who is smaller than the rest,
the "runt." They have a natural fear of bigger creatures and as such will back away
at the first sign of aggression or superiority. I wanted to simulate that in this
proram. When the mouse is unpressed, the square will curiously inspect your cursor.
When the mouse is depressed with slight force, the square will shakily back away,
trying to find refuge on the screen, just like a runt puppy.
*/
float x = 200;
float y = 200;
float easing = 0.01;
float rand = 1;
void setup() {
size(400, 400);
frameRate(60);
smooth();
noStroke();
mouseReleased();
}
//Following
void draw() {
background(0);
fill (200);
rect(x, y, 20, 20);
float targetX = mouseX;
float targetY = mouseY;
//Quivering and Avoidance
if (mousePressed){
x -= (targetX - x) * easing;
y -= (targetY - y) * easing;
x += random(-rand, rand);
y += random(-rand, rand);
}
else
{
x += (targetX - x) * easing;
y += (targetY - y) * easing;
}
x = constrain(x, 0, width);
y = constrain(y, 0, height);
}
Dougal - H
on Tuesday, Oct 21, 2008 – 9:02 pm