| private void makeMandelbrotSet() |
| { |
| |
| Graphics gScreen = this.CreateGraphics(); |
| Size sz = this.ClientSize; |
| bmp = new Bitmap(sz.Width, sz.Height); |
| Graphics gBitmap = Graphics.FromImage(bmp); |
| Pen p = Pens.Black; |
| |
| Pen[] colorPens = new Pen[72]; |
| colorPens[0] = Pens.AliceBlue; |
| colorPens[1] = Pens.AntiqueWhite; |
| colorPens[2] = Pens.Aqua; |
| colorPens[3] = Pens.Aquamarine; |
| colorPens[4] = Pens.Azure; |
| colorPens[5] = Pens.Beige; |
| colorPens[6] = Pens.Bisque; |
| colorPens[7] = Pens.BlanchedAlmond; |
| colorPens[8] = Pens.Blue; |
| colorPens[9] = Pens.BlueViolet; |
| colorPens[10] = Pens.Brown; |
| colorPens[11] = Pens.BurlyWood; |
| colorPens[12] = Pens.CadetBlue; |
| colorPens[13] = Pens.Chartreuse; |
| colorPens[14] = Pens.Chocolate; |
| colorPens[15] = Pens.Coral; |
| colorPens[16] = Pens.CornflowerBlue; |
| colorPens[17] = Pens.Cornsilk; |
| colorPens[18] = Pens.Crimson; |
| colorPens[19] = Pens.Cyan; |
| colorPens[20] = Pens.DarkBlue; |
| colorPens[21] = Pens.DarkCyan; |
| colorPens[22] = Pens.DarkGoldenrod; |
| colorPens[23] = Pens.DarkGray; |
| colorPens[24] = Pens.DarkGreen; |
| colorPens[25] = Pens.DarkKhaki; |
| colorPens[26] = Pens.DarkMagenta; |
| colorPens[27] = Pens.DarkOliveGreen; |
| colorPens[28] = Pens.DarkOrange; |
| colorPens[29] = Pens.DarkOrchid; |
| colorPens[30] = Pens.DarkRed; |
| colorPens[31] = Pens.DarkSalmon; |
| colorPens[32] = Pens.DarkSeaGreen; |
| colorPens[33] = Pens.DarkSlateBlue; |
| colorPens[34] = Pens.DarkSlateGray; |
| colorPens[35] = Pens.DarkTurquoise; |
| colorPens[36] = Pens.DarkViolet; |
| colorPens[37] = Pens.DeepPink; |
| colorPens[38] = Pens.DeepSkyBlue; |
| colorPens[39] = Pens.DimGray; |
| colorPens[40] = Pens.DodgerBlue; |
| colorPens[41] = Pens.Firebrick; |
| colorPens[42] = Pens.FloralWhite; |
| colorPens[43] = Pens.ForestGreen; |
| colorPens[44] = Pens.Fuchsia; |
| colorPens[45] = Pens.Gainsboro; |
| colorPens[46] = Pens.GhostWhite; |
| colorPens[47] = Pens.Gold; |
| colorPens[48] = Pens.Goldenrod; |
| colorPens[49] = Pens.Green; |
| colorPens[50] = Pens.GreenYellow; |
| colorPens[51] = Pens.Honeydew; |
| colorPens[52] = Pens.HotPink; |
| colorPens[53] = Pens.IndianRed; |
| colorPens[54] = Pens.Indigo; |
| colorPens[55] = Pens.Ivory; |
| colorPens[56] = Pens.Khaki; |
| colorPens[57] = Pens.Lavender; |
| colorPens[58] = Pens.LavenderBlush; |
| colorPens[59] = Pens.LawnGreen; |
| colorPens[60] = Pens.LemonChiffon; |
| colorPens[61] = Pens.LightBlue; |
| colorPens[62] = Pens.LightCoral; |
| colorPens[63] = Pens.LightCyan; |
| colorPens[64] = Pens.LightGoldenrodYellow; |
| colorPens[65] = Pens.LightGray; |
| colorPens[66] = Pens.LightYellow; |
| colorPens[67] = Pens.Lime; |
| colorPens[68] = Pens.LimeGreen; |
| colorPens[69] = Pens.Maroon; |
| colorPens[70] = Pens.MediumAquamarine; |
| colorPens[71] = Pens.Orange; |
| |
| |
| const double xLBound = -1.0; |
| const double xUBound = -0.5; |
| const double yLBound = -0.50; |
| const double yUBound = 0.50; |
| const int maxIter = 50; |
| |
| Complex TopLeft = new Complex(); |
| TopLeft.a = xLBound; |
| TopLeft.b = yUBound; |
| |
| Complex BottomRight = new Complex(); |
| BottomRight.a = xUBound; |
| BottomRight.b = yLBound; |
| |
| int xPixels = this.ClientSize.Width; |
| int yPixels = this.ClientSize.Height; |
| |
| double xDelta = (BottomRight.a - TopLeft.a) / xPixels; |
| double yDelta = (TopLeft.b - BottomRight.b) / yPixels; |
| |
| Complex current = TopLeft; |
| bool inSet; |
| |
| for (int x = 0; x < xPixels; x++) |
| { |
| for (int y = 0; y < yPixels; y++) |
| { |
| inSet = true; |
| Complex complexTest = current; |
| |
| int numIter = 0; |
| for (int iterations = 1; iterations <= maxIter; iterations++) |
| { |
| Complex cs = ComplexMath.Square(complexTest); |
| Complex cf = ComplexMath.Sum(cs, current); |
| |
| if ( (cf.a * cf.a) + (cf.b * cf.b) > 4 ) |
| { |
| inSet = false; |
| if (iterations < colorPens.Length) |
| { |
| numIter = iterations; |
| } |
| else |
| { |
| numIter = colorPens.Length; |
| } |
| break; |
| } |
| complexTest = cf; |
| } |
| |
| if (inSet) |
| { |
| gScreen.DrawLine(p, x, y, x, y + 1); |
| gBitmap.DrawLine(p, x, y, x, y + 1); |
| } |
| else |
| { |
| gScreen.DrawLine(colorPens[numIter-1], x, y, x, y + 1); |
| gBitmap.DrawLine(colorPens[numIter-1], x, y, x, y + 1); |
| } |
| current.b -= yDelta; |
| } |
| current.b = TopLeft.b; |
| current.a += xDelta; |
| } |
| } |