Exemple #1
0
 /// <summary>
 /// Overload for <see cref="Render(Size, ImageInfo, IProgressBar, bool)"/>.
 /// Use if a progress reporting isn't required
 /// </summary>
 public static Bitmap Render(Size bitmapSize, ImageInfo imageInfo)
 {
     return(Render(bitmapSize, imageInfo, progressBar: null, reportProgress: false));
 }
Exemple #2
0
        private static void CalculatePixels(
            byte[] pixels,
            Size bitmapSize,
            ImageInfo imageInfo,
            int startRow,
            int endRow,
            int totalRows,
            IProgressBar progressBar,
            bool reportProgress)
        {
            double axisWidth   = imageInfo.AxisWidth;
            double planeHeight = imageInfo.AxisHeight;

            var focusPoint = imageInfo.FocusPoint;

            int bitmapWidth  = bitmapSize.Width;
            int bitmapHeight = bitmapSize.Height;

            /* converts the pixel coordinate to the equivalent coordinate on the given
             * portion of the complex plane. */

            for (int row = startRow; row < endRow; row++)
            {
                for (int column = 0; column < bitmapSize.Width; column++)
                {
                    // the real part of C will be the X coordinate
                    double c_real = ((column - bitmapWidth / 2) * axisWidth / bitmapWidth)
                                    + focusPoint.X;

                    // the imaginary part of C will be the Y coordinate
                    double c_im = (-(row - bitmapHeight / 2) * planeHeight / bitmapWidth)
                                  + focusPoint.Y;

                    double z_real = 0;
                    double z_im   = 0;

                    int iteration = 0;

                    while (z_real * z_real + z_im * z_im < 4 && iteration < MAX_ITERATIONS)
                    {
                        double z_real_tmp = z_real * z_real - (z_im * z_im) + c_real;

                        z_im   = 2 * z_real * z_im + c_im;
                        z_real = z_real_tmp;

                        iteration++;
                    }

                    Color color;

                    if (iteration < MAX_ITERATIONS)
                    {
                        color = ColorHelper.BLUE_BROWN[iteration % ColorHelper.BLUE_BROWN.Length];
                    }
                    else
                    {
                        color = Color.Black;
                    }

                    int i = ((row * bitmapWidth) + column) * COLORS_PER_PIXEL;

                    pixels[i]     = color.B;
                    pixels[i + 1] = color.G;
                    pixels[i + 2] = color.R;
                }

                if (reportProgress && row % REPORT_ROW_INTERVAL == 0)
                {
                    OnCalculatedRow(progressBar, totalRows);
                }
            }
        }