Add Conway draft

master
Fabien Freling 2019-03-29 14:05:25 +01:00
parent ddbe443f92
commit 333e8eb317
1 changed files with 100 additions and 0 deletions

100
conway.lua Normal file
View File

@ -0,0 +1,100 @@
-- title: Conway TIC of life
-- author: Fabien Freling
-- desc: short description
-- script: lua
t=0
width=240
height=136
buffer={}
ib={} -- integral-buffer
for i=0,width*height-1 do
buffer[i]=0
end
-- initial state
buffer[11+10*width]=1
buffer[12+10*width]=1
buffer[13+10*width]=1
function display()
for y=0,height-1 do
for x=0,width-1 do
local color=0
if buffer[x+y*width]==1 then
color=13
end
pix(x,y,color)
end
end
end
function compute_ib()
for i=0,width*height-1 do
ib[i]=buffer[i]
end
for x=1,width-1 do
ib[x]=ib[x]+ib[x-1]
end
for y=1,height-1 do
ib[y*width]=ib[y*width]+ib[(y-1)*width]
end
for y=1,height-1 do
for x=1,width-1 do
ib[x+y*width]=ib[x+y*width]+ib[x-1+y*width]+ib[x+(y-1)*width]
end
end
end
function update()
compute_ib()
-- deal with border later
for y=2,height-3 do
for x=2,width-3 do
i=x+y*width
local n=ib[x+1+(y+1)*width]-ib[x-2+(y+1)*width]-ib[x+1+(y-2)*width]+ib[x-2+(y-2)*width]
n=n-buffer[i]
if n < 2 then
buffer[i]=0
elseif n == 3 then
buffer[i]=1
else
buffer[i]=0
end
end
end
end
function TIC()
display()
if btn(0) then update() end
if btn(1) then update() end
if btn(2) then update() end
if btn(3) then update() end
t=t+1
end
-- <TILES>
-- 001:efffffffff222222f8888888f8222222f8fffffff8ff0ffff8ff0ffff8ff0fff
-- 002:fffffeee2222ffee88880fee22280feefff80fff0ff80f0f0ff80f0f0ff80f0f
-- 003:efffffffff222222f8888888f8222222f8fffffff8fffffff8ff0ffff8ff0fff
-- 004:fffffeee2222ffee88880fee22280feefff80ffffff80f0f0ff80f0f0ff80f0f
-- 017:f8fffffff8888888f888f888f8888ffff8888888f2222222ff000fffefffffef
-- 018:fff800ff88880ffef8880fee88880fee88880fee2222ffee000ffeeeffffeeee
-- 019:f8fffffff8888888f888f888f8888ffff8888888f2222222ff000fffefffffef
-- 020:fff800ff88880ffef8880fee88880fee88880fee2222ffee000ffeeeffffeeee
-- </TILES>
-- <WAVES>
-- 000:00000000ffffffff00000000ffffffff
-- 001:0123456789abcdeffedcba9876543210
-- 002:0123456789abcdef0123456789abcdef
-- </WAVES>
-- <SFX>
-- 000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000304000000000
-- </SFX>
-- <PALETTE>
-- 000:140c1c44243430346d4e4a4e854c30346524d04648757161597dced27d2c8595a16daa2cd2aa996dc2cadad45edeeed6
-- </PALETTE>