public void TestSimple()
 {
     Mandelbrot m = new BasicMandelbrot(64);
     MandelbrotView view = new TrajectoryMandelbrotView(m, new StaticTrajectory(0, 0, 4), 640, 480);
     Assert.AreEqual(1.0f, view.pixelAt(320, 240));
     Assert.AreEqual(0.0f, view.pixelAt(0, 0));
     Assert.AreEqual(0.0f, view.pixelAt(640, 480));
 }
        public override void initContent(SurfaceImageSourceTarget target, DrawingSize pixelSize)
        {
            this.drawingSize = pixelSize;
            this.size = new DrawingSize((int) (pixelSize.Width/scaling), (int) (pixelSize.Height/scaling));
            context = target.DeviceManager.ContextDirect2D;

            Mandelbrot engine = new BasicMandelbrot(iters);
            view = new TrajectoryMandelbrotView(engine, trajectory, size.Width, size.Height);

            data = new int[size.Width * size.Height];

            PixelFormat format = new PixelFormat(Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Ignore);
            BitmapProperties props = new BitmapProperties(format);

            buf = Bitmap.New<int>(context, size, data, props);
        }
 public void TestValueInsideSet()
 {
     Mandelbrot m = new BasicMandelbrot(64);
     Assert.AreEqual(1.0f, m.valueAt(0, 0));
 }
 public void TestValueOutsideSet()
 {
     Mandelbrot m = new BasicMandelbrot(64);
     Assert.AreEqual(0.0f, m.valueAt(3, 0));
 }
        /// <summary>
        /// Run our application until the user quits.
        /// </summary>
        public void Run()
        {
            // Make window active and hide mouse cursor.
            window.PointerCursor = null;
            window.Activate();

            // Infinite loop to prevent the application from exiting.
            while (true)
            {
                // Dispatch all pending events in the queue.
                window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);

                // Quit if the users presses Escape key.
                if (window.GetAsyncKeyState(VirtualKey.Escape) == CoreVirtualKeyStates.Down)
                {
                    return;
                }

                int WIDTH = 1280;
                int HEIGHT = 800;
                Mandelbrot engine = new BasicMandelbrot(64);
                MandelbrotView view = new StaticMandelbrotView(engine, -.875f, 0f, 3f, WIDTH, HEIGHT);

                // Set the Direct2D drawing target.
                d2dContext.Target = d2dTarget;

                int[] data = new int[WIDTH * HEIGHT];
                for (int y = 0; y < HEIGHT; y++)
                {
                    for (int x = 0; x < WIDTH; x++)
                    {
                        float val = view.pixelAt(x, y);
                        int intVal = (int)(255 * val);
                        data[y * WIDTH + x] = 0 | intVal << 16 | intVal << 8 | intVal;
                    }
                }

                DrawingSize size = new DrawingSize(WIDTH, HEIGHT);
                PixelFormat format = new PixelFormat(Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Ignore);
                BitmapProperties props = new BitmapProperties(format);
                RenderTarget target = d2dContext;
                Bitmap buf = Bitmap.New<int>(target, size, data, props);

                // Clear the target and draw some geometry with the brushes we created. Note that rectangles are
                // created specifying (start-x, start-y, end-x, end-y) coordinates; in XNA we used
                // (start-x, start-y, width, height).
                d2dContext.BeginDraw();
                d2dContext.DrawBitmap(buf, 1, BitmapInterpolationMode.Linear);
                d2dContext.EndDraw();

                // Present the current buffer to the screen.
                swapChain.Present(1, PresentFlags.None);
            }
        }