|
Graphics: A Fractal Program Due: Friday, Dec 7, 5:00 PM PART 1 Fractal Snowflake. Use recursion to generate a fractal snowflake. This snowflake is an example of a fractal computation, but we don't need to know anything about fractals to solve it. There are several ways to describe a fractal snowflake. The best way
for this assignment is to first draw an equilateral triangle like this: Then draw a second one on top of this, same size, but rotated 180 degrees (thus generating the Star of David :-). You will note that the upper part of the figure will then look like the version described earlier. Now repeat this process for each of the corners of the figure (there are six of them!), until a suitably small triangle is reached. Draw your snowflake on a Form. Experiment with sizes to get it to look nice (hint: make the form large!). You may want to experiment with filled versus unfilled triangles and different colors for the successively smaller layers. Hint: Perhaps the hardest thing about this assignment is figuring out the coordinates of the various images. I suggest that you start with the smallest version, and then scale it up suitably. There are two things to figure out from a given center: the new centers, and the vertices of the two triangles. If we map this out on a 6-by-6 grid, the centers are given by: (3,1) and the vertices by: (3,0) If this doesn't make sense to you, draw a 6x6 grid and map out the above coordinates. PART 2 Modified Paint Program with Undo Facility. Modify your (or my) solution to Assignment 9 (the Paint Program) so that it keeps track of all line segments that it draws between times that the Clear button is pressed. Each line segment is specified by its endpoints, color, and line width (and thus you will have to define a small data structure to capture this). The sequence of line segments should be represented by some kind of a linked list. Then, do the following:
Hints: First off, using the Design View, add a handler for the Panel's Paint
exception. Suppose this is called Panel_Paint. In this method you
should first grab the Panel's graphics context like this:
|