Your instructor will assign one or more of the following
problems. Submit all appropriate files for grading, including code
files, screen captures, supplemental files (e.g., image files), and
text files.
-
Write a program that draws a triangle in the middle of the
screen, and then the three points of the triangle move a bit after
each frame in a brownian fashion. The color of the triangle (both
the line and the fill) should be random, as should the thickness of
the line. When a user runs your program, clicking the mouse should
result in a new random color and thickness of the line for the
outline of the triangle. When a user presses any key, the inside
color of the triangle should change to a new random color. You
should ensure that the three points never leave the screen. See an
example below.
-
Write a program called
Bubbler
that animates a bubble jittering around the screen in a brownian
fashion, and incorporate the following features:
- When the animation begins, a bubble should appear in the
middle of the screen. The color of the bubble (both the line and
fill) should be random.
- In each frame of the animation, the x-y coordinates of the
bubble should change in a brownian fashion.
- Clicking the mouse should change the location of the bubble
to the location of the mouse click and result in a new
random line color for the outline of the bubble.
- If any key is pressed, the inside color of the bubble
should change to a new random color and the diameter of the
bubble should change in a brownian fashion.
- Ensure that the x-y coordinates never leave the screen
- Ensure that the bubble never has a diameter smaller than 5
pixels nor larger than 50 pixels.
You can see the result of the animation running below. Hint:
Implement one feature at a time.
-
Write a program that extends the dropping ball with gravity example
discussed in the text, see Section 4.2.2. As an example of how the
program should behave, watch this short
video. We suggest that you approach this program as follows:
- Start with the sample code from Section 4.2.2 from the
text, the falling ball with gravity, and modify it so that the ball
falls straight down starting from the top center of the canvas.
- Add the interactive feature that when the user clicks on
the screen, the ball is repositioned to where the user clicked and
falls as usual from there.
- Allow the user to press and hold the mouse, drag it around
and then drop it by releasing the mouse. For this part,
you’ll need to “suspend gravity” from the mouse
press to the mouse release.
- Re-introduce horizontal movement by computing the x
velocity based on how much the mouse has moved since the last drag
event to the mouse release event. Recall that Processing provides
pre-set variables that will be helpful here.
- As a final touch, allow the user to
stop()
the
animation by pressing any key on the keyboard.
-
Write a program called
CandyCane
that creates an animation of a ball travelling left-to-right and
top-to-bottom across the output window. The ball should start at a
random location on the screen, and when it reaches an edge, it
should reappear on the opposite edge. Additional requirements:
- When the user clicks a mouse button, the ball should change
to a random color.
- When the users types a key, the background should be set to
a random color.
- Each time the program is run, the change in x and y should
be different (i.e. it will not always be the case that there is no
overlap between stripes as shown below)
Below is a screenshot after the animation has been running for
several seconds, during which time the user has been clicking the
mouse and typing keys at random intervals:
Checking In
Submit all appropriate files for grading, including code files,
screen captures, supplemental files (e.g., image files), and text
files. We will grade this exercise according to the following
criteria:
- Correctness:
- 50% - Basic animation - Get the basic animation running.
- 40% - Interactivity - Include the required interactive
elements.
- Understandability:
- 5% - Code Documentation - Separate the logical blocks of
your program with useful comments and white space.
- 5% - Header Documentation - Document the code’s basic
purpose, authors and assignment number.
If you work in teams for this homework assignment, be sure to
submit all team members’ names in the code documentation.