예제 #1
0
        public MainPage()
        {
            InitializeComponent();

            //SnapsToDevicePixels = true;
            //SizeToContent = SizeToContent.WidthAndHeight;

            var i = new Image
            {
                Width  = MandelbrotProvider.DefaultWidth,
                Height = MandelbrotProvider.DefaultHeight
            };



            var s = new WriteableBitmap(MandelbrotProvider.DefaultWidth, MandelbrotProvider.DefaultHeight,
                                        // dpi does not seem to matter at this point
                                        PixelFormats.Pbgra32);
            //96, 96, PixelFormats.Pbgra32, null);


            var shift = 0;

            Action Refresh =
                delegate
            {
                var buffer = MandelbrotProvider.DrawMandelbrotSet(shift);

                s.Lock();


                for (int j = 0; j < buffer.Length; j++)
                {
                    s[j] = unchecked ((int)((uint)buffer[j] | 0xff000000));
                    //Marshal.WriteInt32(s.BackBuffer, j * 4, unchecked((int)((uint)buffer[j] | 0xff000000)));
                }

                //s.AddDirtyRect(new Int32Rect(0, 0, MandelbrotProvider.DefaultWidth, MandelbrotProvider.DefaultHeight));
                s.Invalidate();
                s.Unlock();
            };

            var t = new DispatcherTimer();

            t.Tick +=
                delegate
            {
                shift++;
                Refresh();
            };

            t.Interval = TimeSpan.FromMilliseconds(10);
            t.Start();

            Refresh();

            i.Source = s;

            this.Content = i;
        }
예제 #2
0
        public override void init()
        {
            base.resize(MandelbrotProvider.DefaultWidth, MandelbrotProvider.DefaultHeight);

            //Console
            System.Console.WriteLine("init");

            this.buffer = new MemoryImageSource(MandelbrotProvider.DefaultWidth, MandelbrotProvider.DefaultHeight, MandelbrotProvider.DrawMandelbrotSet(0), 0, MandelbrotProvider.DefaultWidth);

            buffer.setAnimated(true);
            buffer.setFullBufferUpdates(true);

            var shift = 0;

            Action onframe = delegate
            {
                var a = MandelbrotProvider.DrawMandelbrotSet(shift);
                for (int i = 0; i < a.Length; i++)
                {
                    a[i] = (int)(0xFF000000u | (uint)a[i]);
                }

                this.buffer.newPixels();
                this.paint(this.getGraphics());

                shift++;
            };

            onframe();

            this.img = this.createImage(buffer);


            var t = new System.Threading.Thread(
                delegate()
            {
                System.Console.WriteLine("Thread start");

                while (true)
                {
                    onframe();

                    Thread.yield();
                }
            }
                )
            {
                IsBackground = true
            };

            t.Start();
        }