Elements of Graphics: Assignment One
Due Midnight, Tues. Sept 16

This assignment should familiarize you with constructing a complex shape by explicitly defining its boundary, get you started with some mouse interaction, and get you to design smooth shapes using multiple small curve segments. You will modify a program that lets the user change an amoeba shape so that the boundary always remains smooth.

The files you should start with are:

ApplicationFrame.java (same as last time)
Amoeba.java

When you compile and run, you should get an image of a yellow amoeba with a pink nucleus. The amoeba is made up of four separate curves, surrounded by a sort of scaffolding, the control polygons of the curves. Moving the vertices of the control polygons changes the shape of the amoeba. Fool around with it and notice that you can introduce sharp corners into the amoeba's boundary by moving the control points. Only when the endpoints (colored green) of the curve control polygons are exactly in line with their two neighbors is the whole boundary smooth.

Your job is to modify the program so that the user can change the boundary of the amoeba without introducing sharp corners. Here is one way to do this (there are others - if you think of something else that you like better, go ahead and do it, and be sure to tell us in the README.txt file).

First, change the MousePressed method so that endpoints cannot be selected. Now notice that every non-endpoint - every movable control point - is next to exactly one endpoint. Call the movable control point the master and the endpoint the slave. Notice that a slave has two masters, but every master has only one slave. When two masters share a slave, let's call them partners.

Now modify the MouseDragged method so that when the master moves, its slave moves along with it, staying exactly in the middle of the line segment connecting the master with its partner. That does it!

To get this to work, we need to be able to calculate the new position for the slave control point. In the picture below, the master is m, the slave is s, and the partner is p. The formula is on the right. Notice that we just average the x values of the master and its partner to get the x value of the slave, and similarly for the y values.


Turn in the files ApplicationFrame.java, Amoeba.java, and README.txt, using the TURNIN procedure from the previous assignment.


Don Fussell