private static IterationValue[,] CalculateIterationDepths(Size imageSize, ComplexNumber topLeft, ComplexNumber bottomRight, int maxIterationDepth, double threshold)
        {
            IterationValue[,] iterations = new IterationValue[imageSize.Width, imageSize.Height];

            double realRange = bottomRight.RealPart - topLeft.RealPart;
            double imaginaryRange = topLeft.ImaginaryPart - bottomRight.ImaginaryPart;

            var mandelbrotComputer = new MandelbrotComputer(maxIterationDepth, threshold);

            double realResolution = realRange / imageSize.Width;
            double imaginaryResolution = imaginaryRange / imageSize.Height;

            Action<int> computeIteration = x =>
            {
                double xResolution = x * realResolution;

                for (int y = 0; y < imageSize.Height; y++)
                {
                    double realPart = topLeft.RealPart + xResolution;
                    double imaginaryPart = topLeft.ImaginaryPart - y * imaginaryResolution;

                    var z = new ComplexNumber(realPart, imaginaryPart);
                    iterations[x, y] = mandelbrotComputer.ComputeIterationDepthFor(z);
                }
            };

            Parallel.For(0, imageSize.Width, computeIteration);

            return iterations;
        }
Пример #2
0
        public void MultiplyWith(ComplexNumber number)
        {
            double currentRealPart = RealPart;

            RealPart = RealPart * number.RealPart - ImaginaryPart * number.ImaginaryPart;
            ImaginaryPart = currentRealPart * number.ImaginaryPart + ImaginaryPart * number.RealPart;
        }
        public byte[] Draw(Size imageSize, ComplexNumber topLeft, ComplexNumber bottomRight, int maxIterationDepth = 199, double threshold = 2.0)
        {
            IterationValue[,] iterations = CalculateIterationDepths(imageSize, topLeft, bottomRight, maxIterationDepth, threshold);

            using (var bitmap = new Bitmap(imageSize.Width, imageSize.Height))
            {
                DrawMandelbrotSet(bitmap, iterations, maxIterationDepth);
                return SaveImageToByteArray(bitmap);
            }
        }
        public ActionResult Drawing(int width, int height, int maxIterationDepth, double threshold,
            double realFrom, double realTo, double imaginaryFrom, double imaginaryTo)
        {
            var imageSize = GetImageSize(width, height);

            var topLeft = new ComplexNumber(realFrom, imaginaryFrom);
            var bottomRight = new ComplexNumber(realTo, imaginaryTo);

            var mandelbrotDrawer = new MandelbrotDrawer();
            byte[] mandelbrotBytes = mandelbrotDrawer.Draw(imageSize, topLeft, bottomRight, maxIterationDepth, threshold);

            return File(mandelbrotBytes, "image/png");
        }
Пример #5
0
 public void Add(ComplexNumber number)
 {
     RealPart      += number.RealPart;
     ImaginaryPart += number.ImaginaryPart;
 }
Пример #6
0
 public void Add(ComplexNumber number)
 {
     RealPart += number.RealPart;
     ImaginaryPart += number.ImaginaryPart;
 }
        private static IterationValue[,] CalculateIterationDepths(Size imageSize, ComplexNumber topLeft, ComplexNumber bottomRight, int maxIterationDepth, double threshold)
        {
            IterationValue[,] iterations = new IterationValue[imageSize.Width, imageSize.Height];

            double realRange      = bottomRight.RealPart - topLeft.RealPart;
            double imaginaryRange = topLeft.ImaginaryPart - bottomRight.ImaginaryPart;

            var mandelbrotComputer = new MandelbrotComputer(maxIterationDepth, threshold);

            double realResolution      = realRange / imageSize.Width;
            double imaginaryResolution = imaginaryRange / imageSize.Height;

            Action <int> computeIteration = x =>
            {
                double xResolution = x * realResolution;

                for (int y = 0; y < imageSize.Height; y++)
                {
                    double realPart      = topLeft.RealPart + xResolution;
                    double imaginaryPart = topLeft.ImaginaryPart - y * imaginaryResolution;

                    var z = new ComplexNumber(realPart, imaginaryPart);
                    iterations[x, y] = mandelbrotComputer.ComputeIterationDepthFor(z);
                }
            };

            Parallel.For(0, imageSize.Width, computeIteration);

            return(iterations);
        }