Advertisement
timeshifter

Untitled

Mar 15th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1.         void ComputeFrame() {
  2.             i = 0;
  3.             x = 0;
  4.  
  5.             //lock the canvas, because i haven't delved into actual bitmap pointer drawing to the screen itself
  6.             bmpData = canvas.LockBits(bmpRect, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
  7.             currPos = (uint*)bmpData.Scan0;
  8.  
  9.             fixed (byte* f = field) { //field contains the entire grid plus swap
  10.                 t = f + w3; //starting point of the current generation
  11.                 a = t; //starting point of the next generation
  12.  
  13.                 //determine which is which
  14.                 if (altFrame)
  15.                     t += outerL;
  16.                 else
  17.                     a += outerL;
  18.  
  19.                 while (i++ < l) {
  20.                     //sum living neighbors
  21.                     n = (uint)(*(t - 1) + *(t + 1) + *(t - w2) + *(t + w2) + *(t - w1) + *(t + w1) + *(t - wp1) + *(t + wp1));
  22.  
  23.                     if (*t == 1) { //current cell is alive
  24.                         *a = (byte)((n >> 1) == 1 ? 1 : 0);
  25.                         //*a = (byte)((n >> 1) & 0x01);
  26.  
  27.                         *currPos = 0xffffffff; // col;
  28.                     }
  29.                     else { //he's dead, jim
  30.                         *a = (byte)(n == 3 ? 1 : 0);
  31.                         //if (fadeColors) { //fancy color cycling and fading, looks cool, but is slow
  32.                         //    if ((*currPos & 0x00ff0000) > (uint)(colLimit << 16)) *currPos -= (uint)(colDecVal << 16);
  33.                         //    if ((*currPos & 0x0000ff00) > (uint)(colLimit << 8)) *currPos -= (uint)(colDecVal << 8);
  34.                         //    if ((*currPos & 0x000000ff) > (uint)(colLimit)) *currPos -= (uint)(colDecVal);
  35.                         //}
  36.                         //else
  37.                         *currPos = 0xff000000;
  38.                     }
  39.  
  40.  
  41.                     currPos++;
  42.                     if (++x == w) {
  43.                         x = 0;
  44.                         a += 3;
  45.                         t += 3;
  46.                     }
  47.                     else {
  48.                         a++;
  49.                         t++;
  50.                     }
  51.                 }
  52.             }
  53.             canvas.UnlockBits(bmpData);
  54.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement