![]() |
Problem Set 9 Due on Tuesday, 12 December at the start of class |
The purpose of this problem set is to give you experience with graphics and animations. In Task 1, you will create sprite classes for some simple animations. In Task 2, you will write an animation of your own choosing!
There is an extra credit challenge in which, you will write the graphics portion of an application that draws a TuggleWorld very like the BuggleWorld grid you know so well.
All code for this assignment is available
in the ps09_programs
folder in the cs111 download
directory on the CS fileserver.
On this problem set, you are encouraged (but not required) to work with a partner as part of a two-person team. The partner may or may not be someone you have partnered with in the past. If you work on a team, your team will submit a single softcopy and hardcopy of the problem set and the same grade will be given to both team members.
All work by a team must be a true collaboration in which members actively work together on all parts of the assignment. It is not acceptable for team members to split up the problems and work on them independently. All programming should be done with both team members working at the same computer console. It is strongly recommended that both team members share the responsibility of "driving" (typing at the keyboard), swapping every so often. The only work that you may do alone is debugging code that you have written together and talking with the instructors and drop-in tutors.
There are many advantages to programming in pairs. People who program in pairs often claim to take less time than those who program alone. By continuously reviewing the code they find bugs sooner. Catching more bugs also leads to higher-quality code. When it comes to problem solving, two heads are better than one, and less time is spent exploring blind alleys. It can be a better learning experience, since team members both learn from and teach each other. And pair programmers often report that the experience is more enjoyable than programming alone. Many empirical studies have confirmed these and other benefits of pair programming. For example, see The Costs and Benefits of Pair Programming and other publications by Laurie Williams.
It's only fair to note that there are drawbacks to programming in
pairs as well. Some pairs take longer to complete a program than
they would individually. A mismatch in the skill level or working style
of pair members can lead to friction between the individuals and
disrupt the work. At Wellesley, the most common problem in pair
programming is finding enough time in common to work together.
You should not choose a partner to program with on this assignment
unless you can schedule at least 10 hours to work together.
To find a partner with a schedule similar to yours, feel free
to post a message on CS111-F06 Q&A
.
Although you clearly can share Java code with your team partner on this assignment, other aspects of the course collaboration policy still hold. In particular, while you can talk with other individuals and teams about high-level problem-solving strategies, you cannot share any Java code with them.
Spinner.java
from Task 1.
.java
files you wrote or
modified from Task 2.
GraphicalTuggleWorld.java
, which will contain your
completed paintTuggleWorld()
method.
ps09_programs
folder, which should include:
Spinners
subdirectory should
contain your final version of Spinner.java
.
MyAnimation
subdirectory should
contain all the necessary code to run your personal animation.
TuggleGraphics
subdirectory with the final version of GraphicalTuggleWorld.java
.
This problem description contains an embedded
AnimationWorld
applet.
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
)
within the Spinners
folder
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 radiusradius
whose center is at the position (x
,y
) in the Java coordinate system. The disk appears to be hanging by a black string from the top of the window and appears to have two sides, one of which is coloredcolor1
, and the other of which is coloredcolor2
. Initially a circle ofcolor1
should be displayed. The spinning motion is simulated by changing the horizontal radius of the oval by the amountdRadius
at every invocation ofupdateState()
. 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
Spinner
class.
These should all be private
.
Spinner()
constructor method specified above.
resetState()
,
updateState()
, and drawState()
described in the
Sprite contract.
Spinner
implementation, run
the animation in the SpinnerShowcase
applet. A correct definition of Spinner
will give rise to the same behavior shown in the test applet
(a copy of which can be found in the Test
subdirectory).
You can use AnimationWorld
to create dazzling
animations that show off your artistry and your programming talents.
Here is a chance to be creative!
For this task, build an animation of your own design. You may use existing sprites that we have studied, but you should create at least one new kind of sprite from scratch and use it.
The MyAnimation
subdirectory of the
ps09_programs
directory contains a copy of the sprites
and animations shown in Lecture 23. 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 create to
MyShowcase.java
.
We will put together a gallery of your work so everyone can see! You can see Erin Stadler's Fall 1999 animation. Some student animations from Spring 2002 can be viewed in the Spring 2002 animation gallery. Some student animations from Fall of 2005 can be viewed in the Fall 2005 animation gallery.
paintTuggleWorld()
method inside the
file GraphicalTuggleWorld.java
in your
ps09_programs/TuggleGraphics
directory.
The paintTuggleWorld()
method takes two parameters, a
TuggleWorld object and a Graphics object. Draw a grid on the Graphics
object according to the number of rows and columns in the given
TuggleWorld. Then draw the state of each cell in the grid, i.e.,
color the cell appropriately, draw a bagel if appropriate, and draw
the highest numbered tuggle in the cell.
Feel free to define auxiliary methods as you see fit.
Note: Your code is not part of the
TuggleWorld class, so you will not have access to the TuggleWorld
instance variables. You will only be able to use
public
TuggleWorld methods (e.g., getRows()
and getCols()
).
The code can be run either as an applet (by loading
GraphicalTuggleWorld.html
into a browser) or as an
application (by typing java GraphicalTuggleWorld
into the
DrJava Interactions pane (or by hitting F2). In either case, the
applet uses a parameter window to accept the name of a file containing
a tgl
script. When you hit the Run button, the Graphical
Tuggle World will create a TuggleWorld and run the script, just as
execFile()
did in PS8. But then, it will attempt to draw
the resulting TuggleWorld state on the screen using the
paintTuggleWorld()
method that you must implement.