Ejemplo n.º 1
0
        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");
            }
        }
Ejemplo n.º 2
0
        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);
        }