Lab 17: Graphics

The goal of this lab is to practice writing programs that use graphics.

1. Introduction and setup

Snowflakes exhibit 12 symmetries: 6 rotational symmetries (you can rotate the snowflake 60, 120, 180, 240, 300, and 360 degrees--- that is, π/3, 2π/3, π, 4π/3, 5π/3, and 2π radians--- and not change the image) and 6 reflective symmetries (you can flip the snowflake about each of the 3 axes and also halfway between each of the size axes). For those of you who have taken modern algebra, this means that the set of symmetries of a snowflake is isomorphic with the dihedral group of order 12.

We're going to write a program that draws snowflake-like images by rotating and reflecting points. Make a new directory for this lab and copy the following files.

hg clone /cslab/class/csci235/lab17
cd lab17

2. Examining the code so far

Compile and run the program SnowFlakes.java. When you press the button, you'll see that it randomly makes white dots appear in the first π/6 slice of the circle. Inspect the code and figure out how it does it.

3. Rotating the dots

Now, modify FlakePainter.java so that for each dot stores in the ArrayLists, we draw not only the dot indicated, but we also draw the same dot rotated π/3 radians, 2π/3 radians, etc.

4. Reflecting the dots

Make a similar modification: this time for each dot, first find the mirror image of that dot rotated about the x-axis, and then rotates the mirror-image π/3 radians, 2π/3 radians, etc. This is in addition to the rotations done for the original dot.

By now you can run the program and watch a snowflake-like image gradually emerge.

5. Speed things up

To make the snowflake grow more quickly, change the program so that every time the button is pressed, 10 dots are added.

6. If you have time

Can you think of a way to change the program so that the images look more like natural snowflakes? Go for it. (But you probably want to commit your work to the hg repository before you make more changes...)

7. Turn in

Turn in the source files that you modified with a command such as

/cslab/class/csci235/bin/handin lab17 *.java

Be sure to include all of your files on a single command.


Thomas VanDrunen, Cary Gray
Last modified: Fri Apr 20 08:02:10 CDT 2012