The basis for this project was to: create a relationship between the mouse and a square centered in the screen. Treat the square as a creature who is anchored to the screen, but with a personality that is revealed as the mouse is moved in different ways (fast, slow, up, down, clicking rapidly, etc.) Incorporate the mousePressed(), mouseReleased(), mouseMoved(), and mouseDragged() functions. The square in my project rotates. It does not like the mouse, and tries to run away from it. Clicking on the square agitates it, and it shrinks. When it can't take the clicking anymore, it blows up. It also changes colors. When dragged, the square gets bigger. When it feels like its too exposed, it shrinks back down to its original state.
PROCESSING
float x = 200;
float y = 200;
float easing = 0.05;
float sizemodifier = 1;
float shrink =1;
float r = 255;
float g = 255;
float b = 255;
float rotatemodifier = 0;
float rotateamount = 0;
void setup()
{
size (400, 400);
smooth ();
noStroke ();
cursor (HAND);
}
void draw ()
{
background (0);
// float d = dist (width/4, height/4, x, y);
float targetX= mouseX;
float targetY = mouseY;
x-= (targetX-x)*easing;
y-= (targetY-y)*easing;
x = constrain(x,30+20*sizemodifier,410-20*sizemodifier);
y = constrain(y,30+20*sizemodifier,410-20*sizemodifier);
fill (153);
fill (r, g, b);
pushMatrix();
translate (x-20, y-20);
rotateamount= rotateamount + rotatemodifier;
rotate (rotateamount);
rect (-20*sizemodifier*shrink, -20*sizemodifier*shrink, 40*sizemodifier*shrink, 40*sizemodifier*shrink);
popMatrix ();
}
void mouseDragged ()
{
sizemodifier+=0.05;
if (sizemodifier>5)
{
sizemodifier = 1;
}
}
void mouseReleased ()
{
shrink -= 0.03;
if (shrink <0)
shrink = 1;
}
void mousePressed ()
{
r= random (150, 255);
g= random (150, 255);
b= random (150, 255);
}
void mouseMoved ()
{
rotatemodifier +=.05;
rotatemodifier = constrain (rotatemodifier, 0, PI/60);
}