Going Around in Circles
CPS 004.1, 24 July 2002
Now put your animating skills to the test by making any kind of shape move around in a circular
path perpetually. You need to modify only the shape's position in order to make it appear to trace
out the path of a circle. However, you will need to think carefully about what tiny change, applied
repeatedly over time, will make a shape appear to move in a circle. The easiest way to do this is to
think about the problem from the shape's perspective, like when you are driving your car around a
curve in the road, rather than from a strictly mathematical perspective.
This assignment is meant to familiarize you with the following
concepts discussed in class and your reading:
- Problem solving
- Using parameters to simplify code
- Inheritance
Specifications
You are to write a Java applet that displays three different shapes,
e.g., a triangle, a hexagon, and
an oval, moving in circles. Each shape moves around its circle
differently, e.g., in a different
direction, at a different speed, or different diameter. Although they
should appear to be behaving
differently, you should create only
one behavior class that extends
GP.Behaviors.Perpetual.
In order to do this, your behavior will need to parameterized properly so
it can be added to any kind
of shape and its creator can control any aspect of its movement.
An example can be seen online
here.
A worked out example can be seen online
here.
Extra Credit
Generalize your circle behavior to trace out the path of any regular shape, given a
number of sides and a length for each side. A regular shape is one whose sides are all the same
length and whose angles between those sides are the same as well. For example, an equilateral
triangle is a three-sided regular shape, a square is a four-sided regular shape, then a pentagon,
then a hexagon, and so on. We can approximate a circle on the computer by making a regular
shape that has 360 sides, each of length one.
What to Submit
When finished, you and your partner should transfer the entire project folder created by Visual
J++ to your respective public_html/cps4 folder in the acpub system and update your course web
page to link to the newly transferred project using the guidelines given
here.