Esempio n. 1
0
        //Zoom in (or out) to the window (=pixel) coordinates specified
        public void Crop(int x1, int y1, int x2, int y2)
        {
            //Window coordinates to mandelbrot coordinates
            double xreal_start, yreal_start, xreal_end, yreal_end;

            WindowCoordsToMandlebrot(x1, y1, 1, out xreal_start, out yreal_start);
            WindowCoordsToMandlebrot(x2, y2, 1, out xreal_end, out yreal_end);
            //Make sure the crop won't get flipped
            CoordinateUtilities.FixRect(ref xreal_start, ref yreal_start, ref xreal_end, ref yreal_end);
            //Make sure you can't zoom out too much
            if (xreal_start < -2)
            {
                xreal_start = -2;
            }
            if (yreal_start < -2)
            {
                yreal_start = -2;
            }
            if (xreal_end > 2)
            {
                xreal_end = 2;
            }
            if (yreal_end > 2)
            {
                yreal_end = 2;
            }
            MandelbrotX      = xreal_start;
            MandelbrotY      = yreal_start;
            MandelbrotWidth  = xreal_end - xreal_start;
            MandelbrotHeight = yreal_end - yreal_start;
            //Fix the aspect ratio of the mandelbrot figure
            FixAspect();
        }
Esempio n. 2
0
 private void panel1_Paint(object sender, PaintEventArgs e)
 {
     if (mMandelbrotBitmap != null)
     {
         if (mMandlebrotZoomer != null)
         {
             //Draw a zoomed mandelbrot image when the animation is running
             Rectangle bmRegion = mMandlebrotZoomer.GetLatestValue();
             if (mMandelbrotBitmapX2)
             {
                 bmRegion.X      *= 2;
                 bmRegion.Y      *= 2;
                 bmRegion.Width  *= 2;
                 bmRegion.Height *= 2;
             }
             e.Graphics.DrawImage(mMandelbrotBitmap, new Rectangle(0, 0, panel1.Width, panel1.Height), bmRegion, GraphicsUnit.Pixel);
         }
         else
         {
             e.Graphics.DrawImage(mMandelbrotBitmap, 0, 0, panel1.Width, panel1.Height);
         }
     }
     if (mIsMouseDown)
     {
         //Draw a nice box when zooming in by mouse drag
         int x1 = mMouseDownPoint.X;
         int x2 = mCurMousePoint.X;
         int y1 = mMouseDownPoint.Y;
         int y2 = mCurMousePoint.Y;
         CoordinateUtilities.FixRect(ref x1, ref y1, ref x2, ref y2);
         e.Graphics.DrawRectangle(Pens.White, x1, y1, x2 - x1, y2 - y1);
     }
 }
Esempio n. 3
0
 //Zoom the mandelbrot with a nice animation
 private void AnimateZoom(int x1, int y1, int x2, int y2)
 {
     if (x1 == x2 || y1 == y2)
     {
         return;
     }
     //Make sure the top-left and bottom-right coords are not reversed
     CoordinateUtilities.FixRect(ref x1, ref y1, ref x2, ref y2);
     mMandelbrotGenerator.Crop(x1, y1, x2, y2);
     //Setup the RectangleAnimator
     mMandlebrotZoomer =
         new RectangleAnimator(
             new Rectangle(0, 0, panel1.Width, panel1.Height),
             new Rectangle(x1, y1, x2 - x1, y2 - y1), 10);
     //Start the animation thread with a high priority to get the smoothest animation possible
     new Thread(AnimThread)
     {
         Priority = ThreadPriority.Highest
     }.Start();
     UpdateMandelbrot();
 }