Beispiel #1
0
        public RazorBitmapFormAntiparents()
        {
            InitializeComponent();

            this.SetStyle(ControlStyles.DoubleBuffer, false);
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.Opaque, true);

            SimpleParticlesWorld.Size = this.ClientSize;

            this.task = Task.Factory.StartNew(() =>
            {
                using (Graphics graphics = this.CreateGraphics())
                {
                    IntPtr hdc = IntPtr.Zero;
                    try
                    {
                        hdc = graphics.GetHdc();
                        HandleRef handleRef = new HandleRef(graphics, hdc);

                        while (!this.IsTerminate)
                        {
                            this.commonStopwatch.Restart();

                            this.updateStopwatch.Restart();
                            SimpleParticlesWorld.Update();
                            this.updateTime = this.updateStopwatch.ElapsedMilliseconds;

                            this.renderStopwatch.Restart();
                            Array.Clear(this.array, 0, this.array.Length);
                            SimpleParticle particle;
                            int pointBase;
                            for (int i = SimpleParticlesWorld.Particles.Count - 1; i >= 0; --i)
                            {
                                particle = SimpleParticlesWorld.Particles[i];
                                //foreach (SimpleParticle particle in SimpleParticlesWorld.Particles)
                                //{
                                pointBase = (this.size.Height - (int)particle.y) * this.size.Width + (int)particle.x;
                                if (0 <= pointBase && pointBase < this.array.Length)
                                {
                                    this.array[pointBase] = particle.c;
                                }
                            }
                            SetDIBitsToDevice(handleRef, 0, 0, this.size.Width, this.size.Height, 0, 0, 0, this.size.Height, ref this.array[0], ref this.bitmapInfo, 0);
                            this.renderTime = this.renderStopwatch.ElapsedMilliseconds;

                            this.commonTime = this.commonStopwatch.ElapsedMilliseconds;
                        }
                    }
                    finally
                    {
                        if (hdc != IntPtr.Zero)
                        {
                            graphics.ReleaseHdc(hdc);
                        }
                    }
                }
            });
        }
Beispiel #2
0
        private void timer_Tick(object sender, EventArgs e)
        {
            this.commonStopwatch.Restart();

            this.updateStopwatch.Restart();
            SimpleParticlesWorld.Update();
            this.updateTime = this.updateStopwatch.ElapsedMilliseconds;

            this.renderStopwatch.Restart();
            this.razorBitmap.Clear();
            foreach (SimpleParticle particle in SimpleParticlesWorld.Particles)
            {
                this.razorBitmap.SetPixel((int)particle.x, this.razorBitmap.Size.Height - (int)particle.y, particle.c);
            }
            this.razorBitmap.Draw();
            this.renderTime = this.renderStopwatch.ElapsedMilliseconds;

            this.commonTime = this.commonStopwatch.ElapsedMilliseconds;

            this.Text = string.Format("Razor Bitmap. Points count: {0}. Update time: {1}. Render time: {2}. Common time: {3}.", SimpleParticlesWorld.Count, this.updateTime, this.renderTime, this.commonTime);
        }
Beispiel #3
0
 private void Form_MouseUp(object sender, MouseEventArgs e)
 {
     SimpleParticlesWorld.ActionIn(e.X, e.Y);
 }