CST112 -- Project #4:
Joe chases mouse; grass waves at Joe.
Using the "Processing" language,
make a sketch according to the following specifications:
- Make a scene:
sky, field, and grass (plus some text).
- Light-blue sky fills upper quarter of screen, with a circular, yellow sun somewhere near the top.
- Light-brown field in lower three-quarters of screen, with green blades of "grass" at the bottom.
- Use a for-loop to create blades of grass (about 10 or 20 pixels apart), across bottom of screen, .
- Each blade of grass should be 2-pixels thick, and about 20 pixels high,
and all blades must remain parallel to each other, even when they "wave" to follow Joe (see below).
- Don't forget to put some text on the screen, with your name and a title for this sketch.
- Add a creature:
"Joe" is a creature (of your own design, but don't make him too fancy!)
-
who always moves toward the mouse position in every frame.
-
his speed should be such that he would reach the mouse in one second, if he continued.
Calculate how far away Joe is from the mouse, in X and in Y, then divide by 30 to get the DX and DY that would reach the mouse in 30 frames (one second).
- Create some (global) variables to keep track of things:
"center"
and
"position"
-
Create a variable named "center" and set its value to width/2
(the X coordinate of the centerline of the screen.)
- To keep track of Joe's horizontal position on the screen,
create a variable named "position"
whose value will range from -1 (at the left side) to +1 (at the right side).
-
To compute position, subtract center from Joe's X coordinate,
then divide by center.
- Waving grass follows Joe
Each blade should tilt in the same direction,
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
- If Joe is on the centerline of the screen
with a position value of zero,
(X coordinate == center),
then all blades point straight up and the blade in the center points upward at Joe.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
To compute the X coordinate for the top of each blade,
add the same "offset" value to the bottom X coordinate;
that value should be the the length of the blade
multiplied by the position (see above)
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
/
OPTIONAL EXTRAS:
- Make the grass "stretch" -- blades get longer, when Joe is higher on the screen
(i.e. when his Y coordinate is small).
- Sun moves slowly across the sky, from left to right.
- Sun grows dimmer and dimmer, as Joe gets closer to mouse.
- Add eyes to Joe, and make the pupils move (slightly) to look toward the mouse.