Exemple #1
0
 public void SetNext(double cx, double cy, double zoom, double maxIterations)
 {
     src = dst;
     dst = new MandelParameters {
         CenterX = cx, CenterY = cy, Zoom = zoom, MaxIterations = maxIterations
     };
 }
Exemple #2
0
        private double rotation = 0; // angle in radians of rotation

        /// <summary>
        /// Simple mandelbrot rendering
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="angle"></param>
        /// <param name="renderAction"></param>
        void RenderMandelbrot(
            int width, int height,
            MandelParameters parameters,
            double angle,
            Action <int, int, int> renderAction
            )
        {
            var cos   = Math.Cos(angle);
            var sin   = Math.Sin(angle);
            var m     = Math.Max(width, height);
            var scale = 2.0 / (parameters.Zoom * m);

            double temp;

            for (var i = 0; i < width; ++i)
            {
                for (var j = 0; j < height; ++j)
                {
                    // center pixel
                    var cx = i - width / 2.0;
                    var cy = j - height / 2.0;
                    // zoom in
                    cx *= scale;
                    cy *= scale;
                    // rotate
                    temp = cx * cos + cy * sin;
                    cy   = -cx * sin + cy * cos;
                    cx   = temp;
                    // shift
                    cx += parameters.CenterX;
                    cy += parameters.CenterY;

                    // compute iters
                    // z <- z^2+c, which is
                    // x+iy <- (x+iy)^2+(cx+icy), which is
                    // x <- x^2 - y^2 + cx and y <- 2xy+curCenterY
                    double x = cx, y = cy;

                    var count    = 0;
                    var maxIters = (int)parameters.MaxIterations;
                    while (count < maxIters)
                    {
                        if (x * x + y * y > 4.0)
                        {
                            break;
                        }
                        temp = x * x - y * y + cx;
                        y    = 2 * x * y + cy;
                        x    = temp;
                        ++count;
                    }
                    renderAction(i, j, count);
                }
            }
        }