static void DrawTheFractalParallel(NetPbm img) { Parallel.For(0, imageHeight, (yCoordinate) => { double complexY = complexXMinimum + yCoordinate * PixelHeight; if (Math.Abs(complexY) < (PixelHeight / 2)) complexY = 0; for (int xCoordinate = 0; xCoordinate < imageWidth; xCoordinate++) { double complexX = complexXMinimum + xCoordinate * PixelWidth; double Zx = 0.0; double Zy = 0.0; double Zx2 = Zx * Zx; double Zy2 = Zy * Zy; int Iteration; for (Iteration = 0; Iteration < IterationMax && ((Zx2 + Zy2) < ER2); Iteration++) { Zy = 2 * Zx * Zy + complexY; Zx = Zx2 - Zy2 + complexX; Zx2 = Zx * Zx; Zy2 = Zy * Zy; }; if (Iteration == IterationMax) { img.SetColor(xCoordinate, yCoordinate, 0, 0, 0); } else { int mod8, mod4, mod2; mod2 = (mod4 = (mod8 = ((IterationMax - Iteration) % 8)) % 4) % 2; img.SetColor(xCoordinate, yCoordinate, (byte)(mod8 * 63), (byte)(mod4 * 127), (byte)(mod2 * 255)); }; } }); }
static void Main(string[] args) { // System.Diagnostics.Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High; var img = new NetPbm(imageWidth, imageHeight); // DrawTheFractalSequentially(img); DrawTheFractalParallel(img); img.SaveToFile("mandelbrot.ppm"); }