public static Color calcColor(double x, double y, int maxIter, String colorScheme) // returnt kleur van mandelbrotgetal van bijbehorende coordinaten { int colorInt = Mandelbrot.calcIter(x, y, maxIter); Color result; int[] highIterRGB = new int[] { 255, 0, 0 }; // defining the color set for MaxIter and potentially other Color Sets int[] lowIterRGB = new int[] { 0, 255, 0 }; // idem dito double a = (double)colorInt / maxIter; // calculate coefficient for convex combination of high and low arrays int[] resultRGB = new int[3]; if (colorScheme == "Rainbow") { /** * The Rainbow */ resultRGB[0] = (int)((Math.Sin((double)colorInt * 0.1) + 1) * 126); resultRGB[1] = (int)((Math.Sin((double)(colorInt - 80) * 0.1) + 1) * 126); resultRGB[2] = (int)((Math.Sin((double)(colorInt - 160) * 0.1) + 1) * 126); } else if (colorScheme == "Grass") { resultRGB[0] = (int)((Math.Sin((double)(colorInt - 80) * 0.01) + 1) * 126); resultRGB[1] = (int)((Math.Sin((double)(colorInt) * 0.01) + 1) * 126); resultRGB[2] = (int)((Math.Sin((double)(colorInt - 160) * 0.01) + 1) * 126); } else if (colorScheme == "MaxIter") { for (int i = 0; i < 3; i++) { resultRGB[i] = (int)(a * highIterRGB[i] + (1 - a) * lowIterRGB[i]); } } else if (colorScheme == "White") { if (colorInt % 2 == 0 && colorInt != maxIter) { resultRGB[0] = 255; resultRGB[1] = 255; resultRGB[2] = 255; } } else { resultRGB[0] = (int)Math.Pow(colorInt % 255, 2) / 500 + 100; resultRGB[1] = (int)Math.Pow((colorInt - 128) % 255, 2) / 500 + 100; resultRGB[2] = (int)Math.Pow((colorInt - 296) % 255, 2) / 500 + 100; } result = Color.FromArgb(resultRGB[0], resultRGB[1], resultRGB[2]); if (colorInt == maxIter) { result = Color.Black; } return(result); }
private void redrawBitmap() // berekent opnieuw de bitmap en update de picturebox om de verandering te laten zien { Graphics gr = Graphics.FromImage(this.mandelbrotBM); // Voor elke pixel worden de wiskundige coordinaten uitgerekend // De pixel wordt vervolgens gekleurd naar de juiste kleur for (int i = 0; i < this.mandelbrotBM.Width; i++) { for (int j = 0; j < this.mandelbrotBM.Height; j++) { double x = (i - (double)this.mandelbrotBM.Width / 2) * this.scale + this.centerX; double y = (j - (double)this.mandelbrotBM.Height / 2) * this.scale + this.centerY; this.mandelbrotBM.SetPixel(i, j, Mandelbrot.calcColor(x, y, this.maxIter, this.colorScheme)); } } gr.DrawImage(this.mandelbrotBM, 0, 0, this.mandelbrotBM.Width, this.mandelbrotBM.Height); mandelbrotPB.Image = this.mandelbrotBM; }