Ningow

Life.Lua

Nov 3rd, 2020
47
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function init()
  2.     setName("Life")
  3.     setDesc("Conway's game of life Sim")
  4.     setSize(75,8+24+64+8+8+7+4)
  5.     addOutput(24+32)
  6.     addInput("",24+32)
  7.     --addInput("UV",18+24+64+8)
  8.     addParameter("Cut","Lightness Cut",24+64+8,0,0,100)
  9.     addParameter("Tick","Iterations",24+64+8+15,0,0,15)
  10. end
  11. -- A B C
  12. -- D i E
  13. -- F G H
  14.  
  15. function iterate()
  16.     for i=0, tileSize*tileSize-1 do
  17.         x = i%tileSize
  18.         y = math.floor(i/tileSize)
  19.         neigh = 0
  20.        
  21.         a = ((x-1)%tileSize)+(((y-1)%tileSize)*tileSize)
  22.         b = ((x)%tileSize)+(((y-1)%tileSize)*tileSize)
  23.         c = ((x+1)%tileSize)+(((y-1)%tileSize)*tileSize)
  24.         d = ((x-1)%tileSize)+(((y)%tileSize)*tileSize)
  25.         e = ((x+1)%tileSize)+(((y)%tileSize)*tileSize)
  26.         f = ((x-1)%tileSize)+(((y+1)%tileSize)*tileSize)
  27.         g = ((x)%tileSize)+(((y+1)%tileSize)*tileSize)
  28.         h = ((x+1)%tileSize)+(((y+1)%tileSize)*tileSize)
  29.        
  30.         fut[i] = uni[i]
  31.        
  32.         neigh = uni[a] + uni[b] + uni[c] + uni[d] + uni[e] + uni[f] + uni[g] + uni[h]
  33.        
  34.         if uni[i] == 1 and(neigh==2 or neigh==3)then
  35.             fut[i] = 1
  36.         elseif uni[i] == 0 and neigh==3 then
  37.             fut[i] = 1
  38.         else fut[i] = 0
  39.         end
  40.        
  41.     end
  42. end
  43.  
  44. function updateuni()
  45.     for i=0, tileSize*tileSize-1 do
  46.         uni[i] = fut[i]
  47.     end
  48. end
  49.  
  50. function apply()
  51.     --math.randomseed (getValue(5,0,0,1))
  52.     uni = {}
  53.     fut = {}
  54.     cut = getValue(1,0,0,100)
  55.     ticks = getValue(2,0,0,1)
  56.     x = 0
  57.     y = 0
  58.     tileSize = getTileSize()
  59.     for i=0, tileSize*tileSize-1 do
  60.         x = i%tileSize
  61.         y = math.floor(i/tileSize)
  62.         if getValue(0,x,y,1) <= cut then
  63.         out = 0
  64.         else out = 1
  65.         end
  66.         uni[i] = out
  67.     end
  68.     if ticks > 0 then
  69.         for i=0, ticks-1 do
  70.             iterate()
  71.             updateuni()
  72.         end
  73.     end
  74.    
  75.     for i=0, tileSize*tileSize-1 do
  76.         x = i%tileSize
  77.         y = math.floor(i/tileSize)
  78.         out = uni[i]
  79.         setPixel(0,x,y,out,out,out)
  80.     end
  81. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×