# Draw a recursive overlapping snowflake fractal in C#   The example Draw a recursive snowflake fractal in C# explains how to use an iterator and a generator to draw a snowflake fractal. This example uses the same technique with the initiator and generator shown in the second and third pictures above to create an overlapping snowflake fractal.

The code that draws the curve is the same as before. The only difference between this example and the previous one is the following code, which defines the initiator and generator.

```// Coordinates of the points in the initiator.
private List<PointF> Initiator;

// Angles and distances for the generator.
private float ScaleFactor;
private List<float> GeneratorDTheta;

private void btnGo_Click(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
Application.DoEvents();

// Define an initiator and generator.
Initiator = new List<PointF>();
float sqrt_3 = (float)Math.Sqrt(3.0);
float side1 = (picCanvas.ClientSize.Height - 10f) / 2f;
float side2 =
(picCanvas.ClientSize.Width - 10f) / 2f / sqrt_3 * 2f;
float side = Math.Min(side1, side2);
float height = side * sqrt_3 / 2f;
float y1 = (picCanvas.ClientSize.Height - 2 * side) / 2;
float y2 = y1 + side / 2;
float y3 = y2 + side;
float y4 = y1 + 2 * side;
float x1 = (picCanvas.ClientSize.Width - 2 * height) / 2;
float x2 = x1 + height;
float x3 = x2 + height;

//// Initiator for drawing a single generator.
//Initiator = new List<PointF>();
//    picCanvas.ClientSize.Height / 3));
//    picCanvas.ClientSize.Width - 5,
//    picCanvas.ClientSize.Height / 3));

ScaleFactor = (float)(1.0 / 3.0);

GeneratorDTheta = new List<float>();
float pi_over_3 = (float)(Math.PI / 3f);

// Get the parameters.
int depth = int.Parse(txtDepth.Text);

Bitmap bm = new Bitmap(
picCanvas.ClientSize.Width,
picCanvas.ClientSize.Height);
picCanvas.Image = bm;

// Draw the snowflake.
using (Graphics gr = Graphics.FromImage(bm))
{
gr.SmoothingMode = SmoothingMode.AntiAlias;
DrawSnowflake(gr, depth);
}

this.Cursor = Cursors.Default;
}```

This code initializes the Initiator and GeneratorDTheta lists. It then calls the DrawSnowflake method to draw the fractal.

Note that the code includes a commented out section that makes the initiator include only a single line segment. That code makes the program draw the single generator shown in the third picture at the top of the post.

The rest of this initialization code is confusing but straightforward. It simply performs the calculations needed to perform the initializations for the overlapping snowflake fractal.    This entry was posted in fractals, graphics and tagged , , , , , , , , , , , , , . Bookmark the permalink.

### 1 Response to Draw a recursive overlapping snowflake fractal in C#

1. Dean says:

How to draw Brownian tree snowflake fractals? Please show in this site.

good works…