コード例 #1
0
        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;
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        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;
 }
コード例 #7
0
        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);
        }