public void GenerateSet() { try { this.ZExponent = Convert.ToInt32(this.ZExpTB.Text); this.CExponent = Convert.ToInt32(this.CExpTB.Text); RenderProgress.Minimum = 0; RenderProgress.Maximum = 1045; this.width = ClientRectangle.Width; this.height = ClientRectangle.Height; this.ZoomScale = Convert.ToDouble(this.zoom.Text); if (Convert.ToInt32(IterationsTB.Text) > 255) { this.IterationsTB.Text = "255"; this.MaxIter = 255; } else if (Convert.ToInt32(IterationsTB.Text) < 0) { this.IterationsTB.Text = "255"; this.MaxIter = 255; } else { this.MaxIter = Convert.ToInt32(IterationsTB.Text); } GraphicsObject.Clear(Color.Black); Refresh(); Color thisColour = Color.Blue; Color lastColour = Color.Red; double Normalized = 0; XDisposition = Convert.ToDouble(XDispTB.Text); YDisposition = Convert.ToDouble(YDispTB.Text); CValue.Real = Convert.ToDouble(CRealTb.Text); CValue.Imaginary = Convert.ToDouble(CImagTb.Text); Color last = Color.Red; int line = 0; int iLast = 0; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { ZValue.Real = 1.5 * (x - width - 1 / 2) / (0.5 * ZoomScale * width) + XDisposition; ZValue.Imaginary = 1.0 * (y - height - 1 / 2) / (0.5 * ZoomScale * height) + YDisposition; int i = 0; if (this.ZExponent == 2 && this.CExponent == 0) { do { ZValue = ComplexMath.SquarePlus(ZValue, CValue); Normalized = ComplexMath.SquareModulus(ZValue); i++; } while (Normalized < 4.0 && i < MaxIter); } else if (this.ZExponent != 2 && this.CExponent == 0) { do { ZValue = ComplexMath.PowerPlusConst(ZValue, ZExponent, CValue); Normalized = ComplexMath.SquareModulus(ZValue); i++; } while (Normalized < 4.0 && i < MaxIter); } else { do { ZValue = ComplexMath.PowerPlusConst(ZValue, ZExponent, ComplexMath.Power(CValue, CExponent)); Normalized = ComplexMath.SquareModulus(ZValue); i++; } while (Normalized < 4.0 && i < MaxIter); } Color col; if (i == iLast) { col = last; } else { col = Colours[i]; } Canvas.SetPixel(x, y, col); } line++; if (line % 120 == 0) { RenderProgress.Value = line; Refresh(); } } RenderProgress.Value = line; Refresh(); } catch (Exception e) { MessageBox.Show(e.Message); } }
public void RenderImage() { try { RenderProgress.Minimum = 0; RenderProgress.Maximum = 625; XMaxLabel.Text = Convert.ToString("xMax: " + this.MaximumXValue); YMaxLabel.Text = Convert.ToString("yMax: " + this.MaximumYValue); XMinLabel.Text = Convert.ToString("xMin: " + this.MinimumXValue); YMinLabel.Text = Convert.ToString("yMin: " + this.MinimumYValue); if (Convert.ToInt32(this.IterationsTextbox.Text) > 0) { this.MaximumIterations = Convert.ToInt32(IterationsTextbox.Text); } else { this.IterationsTextbox.Text = "50"; this.MaximumIterations = 50; } int PixelStep = 1; bool grey = Greyscale.Checked ? true : false; GraphicsObject.Clear(Color.Black); int height = (int)GraphicsObject.VisibleClipBounds.Size.Height; int LastIteration = -1; Color Colour; Color LastColour = Color.Red; ComplexNumber BottomLeft = new ComplexNumber(MinimumXValue, MinimumYValue); ComplexNumber TopRight = new ComplexNumber(MaximumXValue, MaximumYValue); Converter = new Conversions(GraphicsObject, BottomLeft, TopRight); IsConverterInitialized = true; ComplexNumber pixel_step = new ComplexNumber(PixelStep, PixelStep); ComplexNumber Step = Converter.GetDeltaMathsCoord(pixel_step); Stopwatch RenderTimer = new Stopwatch(); RenderTimer.Start(); int ZExponent = Convert.ToInt32(ZExponentBox.Value); int CExponent = Convert.ToInt32(CExponentBox.Value); int line_number = 0; int yPixel = FractalCanvas.Height - 1; for (double YRange = MinimumYValue; YRange < MaximumYValue; YRange += Step.Imaginary) { int xPixel = 0; for (double XRange = MinimumXValue; XRange < MaximumXValue; XRange += Step.Real) { ComplexNumber CComplex = new ComplexNumber(XRange, YRange); ComplexNumber ZComplex = new ComplexNumber(0.0, 0.0); Tuple <int, double> IterationsNormalizedTuple = Rendering.GetEscapeIterations(ZExponent, CExponent, ZComplex, CComplex, MaximumIterations); int Iterations = IterationsNormalizedTuple.Item1; double Normalized = IterationsNormalizedTuple.Item2; if (Iterations < MaximumIterations) { Colour = Rendering.GetColourForPixel(Iterations, MaximumIterations, LastIteration, LastColour, Greyscale.Checked, BlackAndWhite.Checked, Normalized); LastColour = Colour; LastIteration = Iterations; if ((xPixel < FractalCanvas.Width) && (yPixel >= 0)) { FractalCanvas.SetPixel(xPixel, yPixel, Colour); } } xPixel += PixelStep; } yPixel -= PixelStep; line_number++; if ((line_number % 120) == 0) { Refresh(); } if ((line_number % 240) == 0) { try { RenderProgress.Value = line_number; } catch (Exception) { RenderProgress.Value = 0; } } } RenderProgress.Value = line_number; Refresh(); UndoData.Push(new MandelbrotData(MaximumIterations, ZoomScale, grey, BlackAndWhite.Checked, MinimumXValue, MaximumXValue, MinimumYValue, MaximumYValue, ZExponent, CExponent)); RenderTimer.Stop(); TimeElapsedLabel.Text = "Elapsed: " + RenderTimer.Elapsed.Seconds + "." + RenderTimer.Elapsed.Milliseconds + " seconds."; RenderProgress.Value = 0; } catch (Exception e2) { MessageBox.Show("Exception Trapped: " + e2.Message, "Error"); } }
public void mouseClickOnForm(object sender, MouseEventArgs e) { bool RunFunction = true; if (!IsConverterInitialized) { RunFunction = false; } if (!DrawJuliaSetEnabled.Checked) { RunFunction = false; } if (!ZoomInEnabled.Checked) { RunFunction = false; } if (!DrawJuliaSetEnabled.Checked && ZoomInEnabled.Checked) { RunFunction = true; } if (DrawJuliaSetEnabled.Checked && !ZoomInEnabled.Checked) { RunFunction = true; } if (RunFunction) { if (ZoomInEnabled.Checked) { DrawJuliaSetEnabled.Checked = false; double x_temp = Convert.ToDouble(e.X); XCoord = x_temp; double y_temp = Convert.ToDouble(e.Y); YCoord = y_temp; try { ZoomScale = Convert.ToInt16(ZoomScaleTextBox.Text); } catch (Exception c) { MBOX("Error: " + c.Message, "Error"); } if (ZoomScale < 1) { MBOX("Zoom scale must be above 0"); ZoomScale = 7; ZoomScaleTextBox.Text = "7"; return; } ComplexNumber pixel_coordinate = new ComplexNumber((int)(XCoord - (BITMAP_WIDTH / (ZoomScale)) / 4), (int)(YCoord - (BITMAP_HEIGHT / (ZoomScale)) / 4)); ZoomCoordinate1 = Converter.GetAbsoluteMathsCoord(pixel_coordinate); } else if (DrawJuliaSetEnabled.Checked) { ZoomInEnabled.Checked = false; Cursor cursor = new Cursor(Cursor.Current.Handle); double x_pixel = Convert.ToDouble(e.X); double y_pixel = Convert.ToDouble(e.Y); ComplexNumber i = new ComplexNumber(x_pixel, y_pixel); ComplexNumber screen_coordinates = Converter.GetAbsoluteMathsCoord(i); JuliaSet j = new JuliaSet(screen_coordinates, Convert.ToInt32(this.ZExponentBox.Text)); j.ShowDialog(); j.Dispose(); } } }
public Bitmap GenerateNewImage(double yMin, double yMax, double xMin, double xMax) { Bitmap newImage = new Bitmap(ClientWidth, ClientHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb ); if (Convert.ToInt32(this.IterationsTextbox.Text) > 0) { this.MaximumIterations = Convert.ToInt32(IterationsTextbox.Text); } else { this.IterationsTextbox.Text = "50"; this.MaximumIterations = 50; } int xyPixelStep = 1; bool grey = Greyscale.Checked ? true : false; GraphicsObject.Clear(Color.Black); int height = (int)GraphicsObject.VisibleClipBounds.Size.Height; int kLast = -1; Color color; Color colorLast = Color.Red; ComplexNumber screenBottomLeft = new ComplexNumber(xMin, yMin); ComplexNumber screenTopRight = new ComplexNumber(xMax, yMax); Converter = new Conversions(GraphicsObject, screenBottomLeft, screenTopRight); IsConverterInitialized = true; ComplexNumber pixelStep = new ComplexNumber(xyPixelStep, xyPixelStep); ComplexNumber xyStep = Converter.GetDeltaMathsCoord(pixelStep); int ZExponent = Convert.ToInt32(ZExponentBox.Text); int CExponent = Convert.ToInt32(CExponentBox.Text); int yPix = FractalCanvas.Height - 1; for (double y = yMin; y < yMax; y += xyStep.Imaginary) { int xPix = 0; for (double x = xMin; x < xMax; x += xyStep.Real) { ComplexNumber CComplex = new ComplexNumber(x, y); ComplexNumber ZComplex = new ComplexNumber(0.0, 0.0); Tuple <int, double> IterationsNormalizedTuple = Rendering.GetEscapeIterations(ZExponent, CExponent, ZComplex, CComplex, MaximumIterations); int Iterations = IterationsNormalizedTuple.Item1; double Normalized = IterationsNormalizedTuple.Item2; if (Iterations < MaximumIterations) { color = Rendering.GetColourForPixel(Iterations, MaximumIterations, kLast, colorLast, Greyscale.Checked, BlackAndWhite.Checked, Normalized); colorLast = color; kLast = Iterations; if ((xPix < newImage.Width) && (yPix >= 0)) { newImage.SetPixel(xPix, yPix, color); } } xPix += xyPixelStep; } yPix -= xyPixelStep; } IterationsTextbox.Text = Convert.ToString(Math.Round(10 + IterationsScaleFactor + Convert.ToInt32(IterationsTextbox.Text))); IterationsScaleFactor += 2; return(newImage); }
public static Tuple <int, double> GetEscapeIterations(int ZExponent, int CExponent, ComplexNumber ZComplex, ComplexNumber CComplex, int MaximumIterations) { int Iterations = 0; double Normalized = 0.0; ExponentStates state; if (ZExponent == 2 && CExponent == 0) { state = ExponentStates.DEFAULT_EXPONENT_VALUES; } else if (ZExponent != 2 && CExponent == 0) { state = ExponentStates.NON_DEFAULT_Z_EXPONENT; } else { state = ExponentStates.ANY_OTHER_CASE; } switch (state) { case ExponentStates.DEFAULT_EXPONENT_VALUES: do { ZComplex = ComplexMath.SquarePlus(ZComplex, CComplex); Normalized = ComplexMath.SquareModulus(ZComplex); Iterations++; } while ((Normalized <= (4)) && (Iterations < MaximumIterations)); break; case ExponentStates.NON_DEFAULT_Z_EXPONENT: do { ZComplex = ComplexMath.PowerPlusConst(ZComplex, ZExponent, CComplex); Normalized = ComplexMath.SquareModulus(ZComplex); Iterations++; } while ((Normalized <= (4)) && (Iterations < MaximumIterations)); break; case ExponentStates.ANY_OTHER_CASE: do { ZComplex = ComplexMath.PowerPlusConst(ZComplex, ZExponent, ComplexMath.Power(CComplex, CExponent)); Normalized = ComplexMath.SquareModulus(ZComplex); Iterations++; } while ((Normalized <= (4)) && (Iterations < MaximumIterations)); break; default: MessageBox.Show("Default Case, No Proper Values inputted"); break; } return(new Tuple <int, double>(Iterations, Normalized)); }
public static ComplexNumber ComplexAdd(ComplexNumber c, ComplexNumber other) { c.Real += other.Real; c.Imaginary += other.Imaginary; return(c); }
public static double SquareModulus(ComplexNumber c) { return(c.Real * c.Real + c.Imaginary * c.Imaginary); }
public static double Modulus(ComplexNumber c) { return(Math.Sqrt(c.Real * c.Real + c.Imaginary * c.Imaginary)); }