# Assignment 8: Sierpinski Triangle

Due: Tuesday, April 21st by 11:59 PM

In this assignment, you will create a program that uses random numbers to create a Sierpinski Triangle and other fractal shapes with a user-specified number of corners.

## Getting Started

Start the Cygwin Bash Shell and run the following commands:

```cd h:
cd CS101
unzip CS101_Assign8.zip
cd CS101_Assign8
```

Leave the Cygwin Bash Shell open.

Start Visual Studio 2008 (from the Start menu, Programming->All Programs->Visual Studio 2008. Choose File->Open->Project/Solution.... Choose the file

H:\CS101\CS101_Assign8\CS101_Assign8.sln

In the Solution Explorer, double click the file Form1.cs. You should see the form in a tab called Form1.cs [Design].

Create a program that draws a Sierpinski triangle, or a similar object with any number of corners. Allow the user to input the number of corners and the number of iterations in textboxes. For extra credit, color the pixels based on how many times each pixel has been drawn.

Here is a screenshot:

## Hints

• Remember your type changes (int) or (double) before the variable or expression. Pixels are integers, but you'll need to calculate positions using doubles. C# is picky about matching types.
• If g is your graphics object, the command: g.clear(this.BackColor); will clear off all previous graphics so you can draw something new.

### Suggested Method

1. Start by creating structure that defines points.
2. Create an array to hold the corner points. Note that the size of the array will be determined by the user.
3. Calculate the positions for the corner points, assign them to the array, and display them on the screen. To start, make the corners at least 4 pixels wide and 4 pixels high so you will be sure to see them.
4. Create a point variable that holds the current point. Randomly choose one of the corner points to give you starting x and y values.
5. Loop the number of times specified by the user, each time calculating a new point position and drawing a 1 x 1 rectangle at that point.

For up to 80% credit, create a Sierpinski Triangle.

For up to 90% credit, use a point structure and array to hold the corner points.

For up to 100% credit, allow the user to choose the number of corner points and correctly draw the corresponding shape. Also clear the graphics before drawing a new shape.

For up to 110% credit, color the pixels using an expression in the FromArgb( ) method that changes the color based on how many times that pixel has been colored in. The colors should change as the program runs.

## Submitting

Before you submit, make sure Visual Studio is closed.

To submit, run the following command from the Cygwin bash shell (making sure that you are in the H:\CS101\CS101_Assign8 folder):

```make submit
```