Beispiel #1
0
        public byte[] Generate(FractalImageSettings input)
        {
            int width  = input.PixelWidth;
            int height = input.PixelHeight;

            var f     = MakeConverter(input);
            var color = MakeBasicColorizer();

            var start = DateTime.Now;
            var sw    = new Stopwatch();

            using (Image <Rgba32> image = new Image <Rgba32>(width, height))
            {
                for (int wp = 0; wp < width; wp++)
                {
                    for (int hp = 0; hp < height; hp++)
                    {
                        var pos = f(Tuple.Create(wp, hp));
                        sw.Start();
                        image[wp, hp] = color(pos);
                        sw.Stop();
                    }
                }
                Console.WriteLine($"Mandelbrot run: {sw.ElapsedMilliseconds} ms.");
                Console.WriteLine($"Generated raw image: {(DateTime.Now - start).TotalSeconds}");
                var result = ToPng(image);
                Console.WriteLine($"Encoded as PNG: {(DateTime.Now - start).TotalSeconds}");
                return(result);
            }
        }
Beispiel #2
0
        private Func <Tuple <int, int>, Tuple <double, double> > MakeConverter(FractalImageSettings input)
        {
            var tx = CoordinateTransformer.CreatePixelTransformer(input.PixelWidth, input.PixelHeight, input.OriginX, input.OriginY, input.LogicalWidth);

            return((pixPos) => tx.TransformToLocal(pixPos.Item1, pixPos.Item2));
        }