예제 #1
0
        public static BitmapSource GenerateBitmapSource(int[] picture, MandelBrotArgs args)
        {
            var pic          = GenerateBitmap(picture, args);
            var bitmapSource = ConvertToBitmapSource(args, pic);

            return(bitmapSource);
        }
예제 #2
0
 private static BitmapSource ConvertToBitmapSource(MandelBrotArgs args, Bitmap pic)
 {
     return(Imaging.CreateBitmapSourceFromHBitmap(pic.GetHbitmap(),
                                                  IntPtr.Zero,
                                                  Int32Rect.Empty,
                                                  BitmapSizeOptions.FromWidthAndHeight((int)args.Size.Width,
                                                                                       (int)args.Size.Height)));
 }
예제 #3
0
 private void MainWindow_Loaded(object sender, RoutedEventArgs e)
 {
     Args = new MandelBrotArgs {
         ZoomBase   = 2,
         ZoomFactor = 7,
         Iterations = 255,
         Size       = new Size(512, 512)
     };
     Picture  = MandelbrotService.GenerateBitmapSource(MandelbrotService.Calculate(Args), Args);
     IsLoaded = true;
 }
예제 #4
0
        public static Bitmap GenerateBitmap(int[] picture, MandelBrotArgs args)
        {
            var pic = new Bitmap((int)args.Size.Width, (int)args.Size.Height, PixelFormat.Format32bppArgb);

            for (var x = 0; x < (long)args.Size.Width; x++)
            {
                for (var y = 0; y < (long)args.Size.Height; y++)
                {
                    var arrayIndex = (y * (int)args.Size.Width) + x;
                    var color      = picture[arrayIndex];
                    pic.SetPixel(x, y, GenerateColor(color));
                }
            }

            return(pic);
        }
예제 #5
0
        public static int[] Calculate(MandelBrotArgs args)
        {
            var zoom = args.RealZoom;

            var picture = new int[(long)(args.Size.Width * args.Size.Height)];

            Parallel.For(0L, (long)args.Size.Height, (height) => {
                for (long width = 0; width < (long)args.Size.Width; width++)
                {
                    var c = new Complex(args.Center.X + ((width - (args.Size.Width / 2)) * zoom) /* -   zoom /2*/,
                                        args.Center.Y - ((height - (args.Size.Height / 2)) * zoom) /*-  zoom /2*/);

                    picture[(long)(width + (height * args.Size.Width))] = MandelBrotFunction(c, new Complex(args.Z.X, args.Z.Y), args.Iterations);
                }
            });
            return(picture);
        }
예제 #6
0
 public static void GenerateDiashow(MandelBrotArgs args, int pictureCount)
 {
     Parallel.For(args.ZoomFactor, args.ZoomFactor + pictureCount, (zoomfactor) => {
         var zoomArgs = new MandelBrotArgs {
             Center = new Point {
                 X = args.Center.X, Y = args.Center.Y
             },
             Iterations = args.Iterations,
             Size       = new Size {
                 Width = args.Size.Width, Height = args.Size.Height
             },
             Z = new Point {
                 X = args.Z.X, Y = args.Z.Y
             },
             ZoomBase   = args.ZoomBase,
             ZoomFactor = zoomfactor
         };
         var bitmap = GenerateBitmap(Calculate(zoomArgs), zoomArgs);
         SavePicture(bitmap, $"pic_{zoomfactor}.png");
     });
 }