This exercise from the textbook should be completed with the following modifications:
Use the "creature" that you completed for Project 1 (page 42).
The size of the output window should be 250 by 250 pixels
Your creature should move with the center of the image following the mouse pointer;
use the mouseX and mouseY system variables and the appropriate arithmetic
calculations to implement this functionality
Control the fill color for the creature using the mouse's x-coordinate and
y-coordinate values; add more red to the fill as the mouse moves from left to
right; add more green to the fill as the mouse moves from top to bottom; there
is no blue in the fill color; the mix of red and green should cause the fill to
be yellow when the mouse moves toward the lower-right corner of the output
window (click "Play Project 2" below to see the effect)
When the mouse button is clicked, display the difference of the pmouseX
minus mouseX system variables to the message window.
(In future projects, this difference will be used to control feastures of your creature (such as legs or eyes.)
Be sure to begin each of programs with comment lines that gives you name and the project identification,
then briefly says what your code is supposed to do (if it works!)
// Joe Bloggs, Project #2 (p2.pde):
// Creature follows the mouse pointer, changes color, etc.
It is also a good idea to add some text to your sketch,
giving your name and providing some sort of title for it.
For example:
text( "Follow the mouse", 40,10);
text( "Joe Bloggs", 10,230);
For extra credit:
the background color should gradually change from white to black based upon the position
of the mouse in the output window; if the mouse is exactly at the upper-left
corner the background color is white; if the mouse is exactly at the lower-right
corner the background is black; at any other location in the output window the
background will be some shade of greyscale which gets darker the closer it comes
to the lower-right corner; to accomplish this requires an arithmetic statement
that starts with the sum of the mouseX and mouseY system variables
and continues by factoring it so the result of the calculation is exactly zero
(0) when the mouse is in the upper-left corner and exactly 255 when it is in the
lower-right corner (correct completion of the formula requires an understanding
of the "order of operations" which is a topic that is presented in Chapter 4)
The completed project with the "Processing" sketch file (the ".pde" file)
should be submitted electronically,
by creating a file named "p2.pde" in your folder,
and pasting the source code into it.