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, pi/3, 2pi /3, pi, 4pi /3, 5pi/3, and 2pi 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.

cp /homes/tvandrun/Public/cs235/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 pi/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 pi/3 radians, 2pi/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 pi/3 radians, 2pi/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.

7. Turn in

Print a hard copy of the files you modified.


Last modified: Wed Dec 2 17:29:11 CST 2009