Graphic by Keith Ohlfs
CS111, Wellesley College, Spring 2002

OPTIONAL Problem Set 10

"Due" Monday May 13, at 11:59pm

[CS111 Home Page] [Syllabus] [Assignments] [Documentation] [FAQ] [CS Dept.] [CWIS]

About this Problem Set

This is an entirely optional extra credit problem set. Your grade in the course will not be adversely affected if you completely ignore this problem set. However, any work that you do on this problem set can potentially earn extra credit points that will improve your course grade.

In particular, the main part of this assignment offers 15 points of problem set credit (compared to the 10 points on past problem sets). Every 3 points of problem set credit contributes 1 point out of 100 to your final grade. So earning a perfect score on this problem set can increase your course grade by 5 points out of 100.

Additionally, this problem set offers 10 more points of additional extra credit in the form of an open-ended extra credit challenge. Extra credit challenge submissions from this assignment (as well as from any previous assignment) will be accepted through 11:59pm on Monday, May 13.

The purpose of this problem set is to give you more experience with Java objects in the context of AnimationWorld. AnimationWorld is a fun context in which to experiment with Java objects you create from scratch.

All code for this assignment is available in the ps10_programs folder in the cs111 download directory on nike.

How to turn in this Problem Set

If you do any part of this optional problem set, you are required to turn in both a hardcopy and a softcopy. For general guidelines on problem set submission, including how to submit a softcopy and how to check if you softcopy submission was successful, click here. Please make sure to keep a copy of your work, either on a zip disk, or in your private directory (or, to play it safe, both).

Hardcopy Submission

Your hardcopy packet should consist of:
  1. The cover page;
  2. The final version of Spinner.java from Task 1;
  3. The final version of Marquee.java from Task 2;
  4. The final version of MorphingPolygon.java from Task 3;
  5. The final version of MyShowcase.java and any other animation and sprite definitions from the Extra Credit Challenge.
Staple these together, and slide the packet under the door of Elena's office (E127, in minifocus).

Softcopy Submission

You should submit your final version of your ps10_programs folder.

Animation World

All problems on this assignment involve AnimationWorld, which was presented in lecture on May 2-3. As part of doing this assignment, you will probably want to review the details of AnimationWorld. You can do this by:

You may also need to consult the contracts of various Java classes while doing the assignment. Real-life Java programmers spend much of their time browsing such contracts!


A Note on Viewing Applets

This problem set description contains several embedded AnimationWorld applets. Experience indicates that these applets usually run OK in the currently installed version of Internet Explorer but may have trouble running in the currently installed version of Netscape. If you cannot get the applets to work in Netscape, try Internet Explorer instead. If neither works, you can run all applets in CodeWarrior from the Test subfolder of ps10_programs.


Task 1: Spinners [4 points]

The following Spinners animation shows "spinning" disks of various sizes and colors:

In this problem, your goal is to flesh out the declaration of the Spinner class (a subclass of Sprite) so that it describes the behavior of spinning two-colored disks. Instances of Spinner should be created via the following constructor method:

public Spinner(int x, int y, int radius, int dRadius, Color color1, Color color2);
Creates a spinning disk with radius radius whose center is at the position (x, y) in the Java coordinate system. The disks appears to have two "sides", one of which is colored color1, and the other of which is colored color2. Initially a circle of color1 should be displayed. The "spinning" motion is simulated by changing the width of the oval by the amount 2*dRadius at every invocation of updateState(). The height of the oval should not change.

For example, the animation shown above is specified as follows:


  import java.awt.*; 

  class SpinnerAnimation extends Animation { 

    public SpinnerAnimation() {
      addSprite(new Spinner(200,100,50,3,Color.red,Color.blue));
      addSprite(new Spinner(250,150,125,1,Color.yellow,Color.green));
      addSprite(new Spinner(300,200,50,5,Color.pink,Color.gray));
      addSprite(new Spinner(400,200,100,2,Color.cyan,Color.magenta));
      setNumberFrames(Animation.NO_MAX_FRAMES);
    }

  }

To complete this problem, you will have to

To test your Spinner implementation, select the Spinners item in PS10Showcase applet. A correct definition of Spinner will give rise to the same behavior shown in the test applet.


Task 2: Marquee [4 points]

The following Marquee animation shows various lines of text that scroll across the screen.

In this problem, your goal is to flesh out the declaration of the Marquee class (a subclass of Sprite) so that it describes the behavior of text that scrolls across the screen. Instances of Marquee should be created via the following constructor method:

public Marquee(String text, Color color, Font font, int y, int dx);
Creates a scrolling line of text displaying the string text in color color and font font. The vertical position of the bottom of the text is determined by the Java y-coordinate y. If dx is negative, the leftmost point of the text starts at the far right end of the applet window and scrolls from right to left, shifting leftward by |dx| units along the x-axis at each invocation of updateState(). If dx is positive, the rightmost point of the text starts at the far left end of the applet window and scrolls from left to right, shifting rightward by |dx| units along the x-axis at each invocation of updateState(). Whenever the line of text has scrolled completely off the screen, it begins scrolling again at the opposite side of the screen.

  import java.awt.*; 

  class MarqueeAnimation extends Animation { 

    public MarqueeAnimation() {
      addSprite(new Marquee("Welcome to CS111", 
                            Color.magenta, 
                            new Font("Serif", Font.BOLD, 75), 
                            100, -5));
      addSprite(new Marquee("Buggles and bagels and pictures and turtles", 
                            Color.cyan, 
                            new Font("SansSerif", Font.ITALIC, 50), 
                            200, -10));
      addSprite(new Marquee("Help! I'm scrolling the wrong way!", 
                            Color.red, 
                            new Font("Monotype", Font.PLAIN, 30), 
                            300, 1));
      setNumberFrames(Animation.NO_MAX_FRAMES);
    }

  }

To complete this problem, you will have to

To test your Marquee implementation, select the Marquee item in PS10Showcase applet. A correct definition of Marquee will give rise to the same behavior shown in the test applet.

Notes:


Task 3: Morphing Polygons [7 points]

The following animation shows a five-sided polygon that "morphs" (changes) over time. It behaves as if each corner of the polygon is a ball that bounces off the edges of the applet window:

The polygon in the above applet is created via the invocation new MorphingPolygon(5,Color.magenta), which specifies a blue polygon with 5 points. The initial positions and velocities of the points are determined randomly every time the animation is reset. Test this by clicking the Reset button. There are many other ways to invoke the MorphingPolygon constructor, which are illustrated via other menu choices in the above applet:

Your goal in this problem is to flesh out the definition of the MorphingPolygon class so that it describes sprites with the behavior shown above. Your class should supports all the different kinds of constructor methods discussed above.

Notes:


Extra Credit Challenge: Open-Ended Animation [up to 10 points]

You can use AnimationWorld to create dazzling animations that show off your artistry and your programming talents. Here is a chance to be creative and earn some extra credit points at the same time.

For this challenge, build an animation of your own design. You may use existing sprites that we have studied, but you should create and use at least one new kind of sprite from scratch.

The MyAnimation subfolder of the ps10_programs folder contains a copy of the sprites and animations shown in lecture 25. This is a good starting point for your own animations. You may edit the existing files or create ones of your own. Add any animations you crete to MyShowcase.java.

If you need help on any aspect of this challenge, do not hesitate to talk to the instructors and/or TAs.

The amount of extra credit awarded on this problem will be proportion to the creativity and artistry in your designs, as well as the level of technical challenge. You can earn up to 10 problem set points in extra credit on this challenge. As an example of an animation worth 10 points, see Erin Stadler's Fall'99 animation.