Advertisement
timeshifter

Untitled

Mar 24th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 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.                         *currPos = 0xffffffff;
  26.                     }
  27.                     else { //he's dead, jim
  28.                         *a = (byte)(n == 3 ? 1 : 0);
  29.                         *currPos = 0xff000000;
  30.                     }
  31.  
  32.                     currPos++;
  33.                     if (++x == w) {
  34.                         x = 0;
  35.                         a += 3;
  36.                         t += 3;
  37.                     }
  38.                     else {
  39.                         a++;
  40.                         t++;
  41.                     }
  42.                 }
  43.             }
  44.             canvas.UnlockBits(bmpData);
  45.         }
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement