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.

  1. 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.

  2. Write a program called Bubbler that animates a bubble jittering around the screen in a brownian fashion, and incorporate the following features:

    1. 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.
    2. In each frame of the animation, the x-y coordinates of the bubble should change in a brownian fashion.
    3. 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.
    4. 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.
    5. Ensure that the x-y coordinates never leave the screen
    6. 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.

  3. 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:

    1. 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.
    2. 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.
    3. 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.
    4. 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.
    5. As a final touch, allow the user to stop() the animation by pressing any key on the keyboard.
  4. 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:

    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:

If you work in teams for this homework assignment, be sure to submit all team members’ names in the code documentation.