private void btn_Update_Click(object sender, EventArgs e) { if (pnl_ColorEditor.Visible == false) { bool parsingSuccess = true; double scale = MaxScale; if (!double.TryParse(txtbx_Scale.Text, out scale) || scale > MaxScale || scale < MinScale || double.IsNaN(scale) || double.IsInfinity(scale)) { txtbx_Scale.ForeColor = Color.Black; txtbx_Scale.BackColor = Color.DarkGoldenrod; parsingSuccess = false; } else { txtbx_Scale.ForeColor = Color.Gray; txtbx_Scale.BackColor = Color.Black; } uint iterationDepth = PaletteManager.IterationLim; if (!uint.TryParse(txtbx_IterationDepth.Text, out iterationDepth) || iterationDepth > MaxIterationDepth || iterationDepth < MinIterationDepth) { txtbx_IterationDepth.ForeColor = Color.Black; txtbx_IterationDepth.BackColor = Color.DarkGoldenrod; parsingSuccess = false; } else { txtbx_IterationDepth.ForeColor = Color.Gray; txtbx_IterationDepth.BackColor = Color.Black; } string centerText = txtbx_Center.Text; centerText = centerText.Replace(" ", ""); centerText = centerText.Replace("(", ""); centerText = centerText.Replace(")", ""); bool centerTextValid = true; foreach (char c in centerText) { switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '.': case ',': case '-': case '+': case 'E': case 'e': break; default: { parsingSuccess = false; centerTextValid = false; break; } } } string[] Coords = centerText.Split(','); if (Coords.Length != 2) { centerTextValid = false; } double centerX = InitialX, centerY = InitialY; bool cX = false, cY = false; if (centerTextValid) { cX = double.TryParse(Coords[0], out centerX) && centerX <= 100 && centerX >= -100 && !double.IsNaN(centerX) && !double.IsInfinity(centerX); cY = double.TryParse(Coords[1], out centerY) && centerY <= 100 && centerY >= -100 && !double.IsNaN(centerY) && !double.IsInfinity(centerY); } if (!centerTextValid || !cX || !cY) { txtbx_Center.ForeColor = Color.Black; txtbx_Center.BackColor = Color.DarkGoldenrod; parsingSuccess = false; } else { txtbx_Center.ForeColor = Color.Gray; txtbx_Center.BackColor = Color.Black; } if (parsingSuccess) { Plot_CenterCoord = new PointD(centerX, centerY); PlotScale = scale; PaletteManager.PaletteLength = (int)(((decimal)iterationDepth / PaletteManager.IterationLim) * PaletteManager.PaletteLength); PaletteManager.IterationLim = iterationDepth; PaletteManager.colorSetup(); updateDisplay(); } } }
private void ProcessLines(Color[,] buffer, int x, int y, int endx, int endy, int width, double adjPlotScale, PointD firstPixelGCoord) { int iColor; Color pixelColor; Color inMandSet = Color.Black; double xCoord, yCoord; int dottedWidth = 16; double alphaDottedLine = (double)180 / 255; int r, g, b; bool juliaMode = false; for (int i = x; i < endx; i++) { for (int j = y; j < endy; j++) { xCoord = i * adjPlotScale + firstPixelGCoord.X; yCoord = firstPixelGCoord.Y - j * adjPlotScale; if (juliaMode) { iColor = juliaPixel(xCoord, yCoord); pixelColor = (iColor >= 0) ? PaletteManager.ColorContainer(iColor) : inMandSet; } else { iColor = mandlebrotPixel(xCoord, yCoord, (int)PaletteManager.IterationLim); pixelColor = (iColor >= 0) ? PaletteManager.ColorContainer(iColor) : inMandSet; } if ((xCoord <= 1 * adjPlotScale && xCoord >= -1 * adjPlotScale && j % (2 * dottedWidth) >= dottedWidth) || (yCoord <= 1 * adjPlotScale && yCoord >= -1 * adjPlotScale && i % (2 * dottedWidth) >= dottedWidth)) { r = ((int)(alphaDottedLine * (255 - pixelColor.R) + (1 - alphaDottedLine) * pixelColor.R)); g = ((int)(alphaDottedLine * (255 - pixelColor.G) + (1 - alphaDottedLine) * pixelColor.G)); b = ((int)(alphaDottedLine * (255 - pixelColor.B) + (1 - alphaDottedLine) * pixelColor.B)); pixelColor = Color.FromArgb(r, g, b); } /*if (iColor == -2) * pixelColor = Color.White; * else if (iColor == -1) * pixelColor = inMandSet; * else * pixelColor = PaletteManager.ColorContainer(iColor);*/ buffer[i, j] = pixelColor; } } }