POV-Ray : Newsgroups : povray.off-topic : Who says .NET is slow...? : Who says .NET is slow...? Server Time
6 Sep 2024 05:17:04 EDT (-0400)
  Who says .NET is slow...?  
From: Mike Raiford
Date: 20 Feb 2009 12:46:00
Message: <499eec58$1@news.povray.org>
1024x768 frame buffer...

Code:

:-D

public partial class Form2 : Form
     {
         Bitmap fireBmp;

         byte[,] fireData;

         Timer t = new Timer();

         Random rnd;

         int w = 1024;
         int h = 768;

         int[] clut;

         public Form2()
         {
             InitializeComponent();
             fireData = new byte[w, h];
             fireBmp = new Bitmap(w, h, 
System.Drawing.Imaging.PixelFormat.Format32bppRgb);
             rnd = new Random();

             clut = new int[256];

             for (int i = 0; i < 256; i++ )
             {
                 if (i >= 0 && i < 64) clut[i] = Color.FromArgb(i * 2, 
0, 0).ToArgb();
                 if (i >= 64 && i < 128) clut[i] = Color.FromArgb(i * 2, 
(i-64) * 4, 0).ToArgb();
                 if (i >= 128 && i < 256) clut[i] = 
Color.FromArgb(255,255, (i-128)*2).ToArgb();
             }

                 t.Interval = (int)(1000 / 30.0);
             t.Tick += new EventHandler(t_Tick);
             t.Start();

             this.SetStyle(ControlStyles.OptimizedDoubleBuffer | 
ControlStyles.ResizeRedraw | ControlStyles.UserPaint | 
ControlStyles.AllPaintingInWmPaint, true);
         }

         void t_Tick(object sender, EventArgs e)
         {
             BitmapData bd = fireBmp.LockBits(new Rectangle(0, 0, w, h), 
System.Drawing.Imaging.ImageLockMode.ReadWrite, 
System.Drawing.Imaging.PixelFormat.Format32bppRgb);

             for(int y = 0; y < (h-1); y++)
             {
                 for(int x = 0; x < w; x++)
                 {
                     if(y == 0)
                     {
                         fireData[x, h-1] = (byte)rnd.Next(255);
                         unsafe
                         {
                             int* pBmp = (int*)bd.Scan0;
                             pBmp[x + (h-1) * bd.Stride / 4] = 
clut[fireData[x, h-1]];
                         }
                     }

                     fireData[x, y] = (byte)((fireData[(x - 1 + w) % w, 
y + 1] +
                                     fireData[(x + 1) % w, y + 1] +
                                     fireData[x, y + 1] +
                                     fireData[x, (y + 2) % h]) / 4);


                     int c = clut[fireData[x, y]];

                     unsafe
                     {
                         int* pBmp = (int*)bd.Scan0;
                         pBmp[x + y*bd.Stride/4] = c;
                     }

                 }
             }

             fireBmp.UnlockBits(bd);
             Refresh();
         }

         protected override void OnPaint(PaintEventArgs e)
         {
             base.OnPaintBackground(e);
             e.Graphics.DrawImage(fireBmp, this.ClientRectangle);
         }
     }


-- 
~Mike


Post a reply to this message


Attachments:
Download 'windowsformsapplication1.exe.dat' (11 KB)

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.