Advertisement
Guest User

Untitled

a guest
Apr 8th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. t?  //is this the first frame?
  2.     c.width+=i=0    //if not, clear the frame and initialize i to 0
  3. :
  4. e=[...Array(5184)].map(_=>Math.random())    //otherwise, create an array filled with random values
  5.  
  6. e=e.map(j=> //for each element of the array...
  7.     (
  8.         x.fillRect(i%96*20,~~(i/96)*20,20,j*20) //draw it to its place on the screen if it's true
  9.     ,
  10.         ([1,95,96,97]   //create an array whose values are the absolute offsets of all neighbors
  11.         .map(x=>e[i+x]+e[i-x])  //assign each value the sum of the negative and positive neighbors
  12.         .reduce((x,y)=>x+y,0)   //compute the total of all values in the array
  13.         |e[i++])==3) //if that value is 3, or it's 2 and the element we're looking at is alive, return true.
  14.     )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement