Assignment 12: Screen Savers

Due: Before class Wednesday, Nov 12

.

Problem Statement

Often it is possible to create a number of shapes in a specific pattern algorithmically (i.e., using a loop and calculating the position, size, speed, direction, etc.). When combined with movement, this has the possibility of producing a very interesting effect, with very little effort. In fact, this is the basis of most screen savers, arguably, an art form.

Screen Savers

For each of the screen savers below, you will complete the createMovers method of the appropriate factory subclass that, given a Canvas and an integer parameter, returns nothing but creates the given number of shapes within the given canvas in a specific pattern. The current Canvas class will work without modification because you will modify the paint and move methods of a separate class that extends Mover.

  1. Racers in a Line
    Modify the paint and move methods of the class Racer such that it draws itself like a rectangle and animates itself by moving straight across the screen from left to right at a random rate (i.e., each time move is called, its speed should be randomly set between 1 and 10). When it reaches the right side it should stop (much like those racing games you see at the local carnival).

    Modify the createMovers method of the class RacerFactory to create the given number of Racers such that they are all the same size and are positioned in a line along the left side of the canvas and exactly fill its height. All Racers, no matter how many will be created, should start at the same center x-coordinate, 0, and have the same width, 20. The rest of their attributes should be set so that the rectangles are spread evenly across the edge of the canvas. For example, given 10 racers to create and a canvas that is 100 pixels wide, they should each be 10 pixels high and positioned with their center y-coordinates at 5, 15, 25, 35, 45, 55, 65, 75, 85, and 95, respectively.

    When run, it should appear like the rectangles are racing to the right side of the window.

  2. Walkers on a Diagonal
    Modify Walker such that it draws itself like a rectangle and animates itself by moving at a constant rate in a random direction (i.e., each time move is called, its angle should be changed randomly. The speed of the Walker should be constant throughout its life.

    Modify WalkerFactory to create the given number of Walkers such that they are all the same size and are positioned in a line diagonally across the canvas with each touching the two adjacent rectangles at their corners. Their position and size should be set so that they are spread evenly across the canvas. For example, given 10 walkers to create and a canvas whose size is 100x200 pixels, you should create 10 walkers that are 10x20 pixels in size and centered at (5, 10), (15, 30), (25, 50), (35, 70), (45, 90), (55, 110), (65, 130), (75, 150), (85, 170), and (95, 190), respectively.

    When run, it should appear like the rectangles taking a random (i.e., drunken) walk.

  3. Interesting Circles

    Modify AttractorFactory to create the given number of Attractors such that they are all the same size and are positioned in a circular pattern with each touching the one beside it (i.e., tangent to each other) like the marks on a clock (if those marks were circles). In this case, their position and size should be set so that they are spread evenly around the perimeter of a circle whose diameter is the minimum of the width and height of the canvas. Recall that the formula for computing the circumference, or perimeter, of a circle is 2 * Math.PI * radius. For example, given 4 attractors to create and a canvas whose size is 100x200 pixels, you should create 4 attractors that are 100x100 pixels in size and centered at approximately (272, 0), (372, 100), (272, 200), and (172, 100), respectively.

    Modify the Attractor such that it draws itself as a circle and animates itself in some "interesting" way. Options include orbiting or swarm effects or simulating dynamical systems.

  4. Extra Credit: Leaving a Trail

    Change the super class, Mover, such that it paints itself as a collection of connected line segments and animates itself by adding the current center of the shape to a collection of points (i.e., each time move is called, the center point is added to a collection). When drawn as a series of lines from the first point to the second point in the collection, from the second point to the third point, from the third point to the fourth point, and on and on until the last point in the collection, it will appear that the shape is leaving a trail behind marking where it has moved. To make the trail appear, each of the previous classes' paint and move methods will need to be modified to call their corresponding super method. Additionally, Mover will need to declare and initialize an instance variable that is a collection of all the past points.

    Since this code is in the superclass, it is inherited by all the sub-classes and it will mark a trail for any of the shapes written above without having to know the exact type of sub-class or movement being made.

Testing

There are no JUnit tests required for this application (why?), but you should make sure you test your application thoroughly so that you know it's working correctly.

Grading Criteria (100)

Your grade will be based on