223 lines
21 KiB
Lua
223 lines
21 KiB
Lua
pico-8 cartridge // http://www.pico-8.com
|
|
version 19
|
|
__lua__
|
|
-- 1-d cellular automata demo
|
|
-- by zep
|
|
-- ref: wikipedia.org/wiki/cellular_automaton
|
|
|
|
cls()
|
|
l=0 -- line count
|
|
|
|
--uncomment for kaleidoscope
|
|
--poke(0x5f2c,7)
|
|
|
|
-- starting rule set
|
|
r={[0]=0,1,0,1,1,0,0,1}
|
|
|
|
|
|
function _update()
|
|
|
|
l+=1
|
|
-- change rule every 16 lines
|
|
-- (or when ❎ is pressed)
|
|
if (l%16==0 or btnp(❎)) then
|
|
for i=1,7 do
|
|
r[i]=flr(rnd(2.3))
|
|
end
|
|
end
|
|
|
|
|
|
-- if the line is blank, add
|
|
-- something to get it started
|
|
|
|
found = false
|
|
for x=0,127 do
|
|
if (pget(x,127)>0) found=true
|
|
end
|
|
|
|
if (not found) then
|
|
pset(63,127,7)
|
|
end
|
|
|
|
end
|
|
|
|
function _draw()
|
|
-- scroll
|
|
memcpy(0x6000,0x6040,0x1fc0)
|
|
|
|
for x=0,127
|
|
do n=0
|
|
for b=0,2 do
|
|
if (pget(x-1+b,126)>0)
|
|
then
|
|
n += 2 ^ b -- 1,2,4
|
|
end
|
|
end
|
|
pset(x,127,r[n]*7)
|
|
end
|
|
|
|
end
|
|
|
|
__gfx__
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000990000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
__label__
|
|
00000000000000000000000000000000000000000000000000000007000000000000000700000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000070700000000000007070000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000700070000000000070007000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000007070707000000000707070700000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000070000000700000007000000070000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000707000007070000070700000707000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000007000700070007000700070007000700000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000070707070707070707070707070707070000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000707070707070707070707070707070700000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000007070707070707070707070707070707000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000070707070707070707070707070707070000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000707070707070707070707070707070700000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000007070707070707070707070707070707000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000070707070707070707070707070707070000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000707070707070707070707070707070700000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000007070707070707070707070707070707000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000070707070707070707070707070707070000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000707070707070707070707070707070700000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000007070707070707070707070707070707000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000070707070707070707070707070707070000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000707070707070707070707070707070700000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000007070707070707070707070707070707000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000070707070707070707070707070707070000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000707070707070707070707070707070700000000000000000000000000000000000000000000000000000000000000000
|
|
000000000000000000000000000000007777777777777777777777777777777e0000000000000000000000000000000000000000000000000000000000000000
|
|
0000000000000000000000000000000007777777777777777777777777777777e000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000007777777777777777777777777777777e00000000000000000000000000000000000000000000000000000000000000
|
|
000000000000000000000000000000000007777777777777777777777777777777e0000000000000000000000000000000000000000000000000000000000000
|
|
0000000000000000000000000000000000007777777777777777777777777777777e000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000007777777777777777777777777777777e00000000000000000000000000000000000000000000000000000000000
|
|
000000000000000000000000000000000000007777777777777777777777777777777e0000000000000000000000000000000000000000000000000000000000
|
|
0000000000000000000000000000000000000007777777777777777777777777777777e000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000007777777777777777777777777777777e00000000000000000000000000000000000000000000000000000000
|
|
000000000000000000000000000000000000000007777777777777777777777777777777e0000000000000000000000000000000000000000000000000000000
|
|
0000000000000000000000000000000000000000007777777777777777777777777777777e000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000007777777777777777777777777777777e00000000000000000000000000000000000000000000000000000
|
|
000000000000000000000000000000000000000000007777777777777777777777777777777e0000000000000000000000000000000000000000000000000000
|
|
0000000000000000000000000000000000000000000007777777777777777777777777777777e000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000007777777777777777777777777777777e00000000000000000000000000000000000000000000000000
|
|
000000000000000000000000000000000000000000000007777777777777777777777777777777e0000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000007000000000000000000000000000000007000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000070700000000000000000000000000000070700000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000700070000000000000000000000000000700070000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000007070707000000000000000000000000007070707000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000070000000700000000000000000000000070000000700000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000707000007070000000000000000000000707000007070000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000007000700070007000000000000000000007000700070007000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000070707070707070700000000000000000070707070707070700000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000700000000000000070000000000000000700000000000000070000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000007070000000000000707000000000000007070000000000000707000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000070007000000000007000700000000000070007000000000007000700000000000000000000000000000000000000
|
|
00000000000000000000000000000000000707070700000000070707070000000000707070700000000070707070000000000000000000000000000000000000
|
|
00000000000000000000000000000000007000000070000000700000007000000007000000070000000700000007000000000000000000000000000000000000
|
|
00000000000000000000000000000000070700000707000007070000070700000070700000707000007070000070700000000000000000000000000000000000
|
|
00000000000000000000000000000000700070007000700070007000700070000700070007000700070007000700070000000000000000000000000000000000
|
|
00000000000000000000000000000007070707070707070707070707070707007070707070707070707070707070707000000000000000000000000000000000
|
|
00000000000000000000000000000007e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7707e7e7e7e7e7e7e7e7e7e7e7e7e7e7e7700000000000000000000000000000000
|
|
000000000000000000000000000000070000000000000000000000000000007e7000000000000000000000000000000770000000000000000000000000000000
|
|
00000000000000000000000000000007700000000000000000000000000000707700000000000000000000000000000777000000000000000000000000000000
|
|
000000000000000000000000000000077700000000000000000000000000007e7770000000000000000000000000000707700000000000000000000000000000
|
|
000000000000000000000000000000070770000000000000000000000000007000770000000000000000000000000007e7770000000000000000000000000000
|
|
00000000000000000000000000000007e77700000000000000000000000000770077700000000000000000000000000700077000000000000000000000000000
|
|
00000000000000000000000000000007000770000000000000000000000000777070770000000000000000000000000770077700000000000000000000000000
|
|
00000000000000000000000000000007700777000000000000000000000000707e7e777000000000000000000000000777070770000000000000000000000000
|
|
000000000000000000000000000000077707077000000000000000000000007e7000007700000000000000000000000707e7e777000000000000000000000000
|
|
0000000000000000000000000000000707e7e77700000000000000000000007077000077700000000000000000000007e7000007700000000000000000000000
|
|
00000000000000000000000000000007e700000770000000000000000000007e7770007077000000000000000000000707700007770000000000000000000000
|
|
00000000000000000000000000000007077000077700000000000000000000700077007e777000000000000000000007e7770007077000000000000000000000
|
|
00000000000000000000000000000007e77700070770000000000000000000770077707000770000000000000000000700077007e77700000000000000000000
|
|
0000000000000000000000000000000700077007e7770000000000000000007770707e7700777000000000000000000770077707000770000000000000000000
|
|
00000000000000000000000000000007700777070007700000000000000000707e7e7007707077000000000000000007770707e7700777000000000000000000
|
|
00000000000000000000000000000007770707e770077700000000000000007e700077077e7e7770000000000000000707e7e700770707700000000000000000
|
|
000000000000000000000000000000e0770000777ee077e00000000000000e077e0e07007777777e00000000000000e0007777ee0700007e0000000000000000
|
|
00000000000000000000000000000e0007e00e077770077e000000000000e000770000ee07777777e000000000000e0e0e07777700e00e07e000000000000000
|
|
0000000000000000000000000000e0e0e07ee000777ee077e0000000000e0e0e07e00e07007777777e0000000000e00000007777ee0ee0007e00000000000000
|
|
000000000000000000000000000e000000077e0e077770077e00000000e00000007ee000ee07777777e00000000e0e00000e077777007e0e07e0000000000000
|
|
00000000000000000000000000e0e00000e0770000777ee077e000000e0e00000e077e0e07007777777e000000e000e000e0007777ee0700007e000000000000
|
|
0000000000000000000000000e000e000e0007e00e077770077e0000e000e000e000770000ee07777777e0000e0e0e0e0e0e0e07777700e00e07e00000000000
|
|
000000000000000000000000e0e0e0e0e0e0e07ee000777ee077e00e0e0e0e0e0e0e07e00e07007777777e00e0000000000000007777ee0ee0007e0000000000
|
|
00000000000000000000000e00000000000000077e0e077770077ee0000000000000007ee000ee07777777ee0e0000000000000e077777007e0e07e000000000
|
|
0000000000000000000000e0e0000000000000e0770000777ee0777e0000000000000e077e0e07007777777700e00000000000e0007777ee0700007e00000000
|
|
000000000000000000000e000e00000000000e0007e00e0777700777e00000000000e000770000ee07777777ee0e000000000e0e0e07777700e00e07e0000000
|
|
00000000000000000000e0e0e0e000000000e0e0e07ee000777ee0777e000000000e0e0e07e00e07007777777700e0000000e00000007777ee0ee0007e000000
|
|
0000000000000000000e0000000e0000000e000000077e0e0777700777e0000000e00000007ee000ee07777777ee0e00000e0e00000e077777007e0e07e00000
|
|
000000000000000000e0e00000e0e00000e0e00000e0770000777ee0777e00000e0e00000e077e0e07007777777700e000e000e000e0007777ee0700007e0000
|
|
00000000000000000e000e000e000e000e000e000e0007e00e0777700777e000e000e000e000770000ee07777777ee0e0e0e0e0e0e0e0e07777700e00e07e000
|
|
0000000000000000e0e0e0e0e0e0e0e0e0e0e0e0e0e0e07ee000777ee0777e0e0e0e0e0e0e0e07e00e0700777777770000000000000000007777ee0ee0007e00
|
|
000000000000000e000000000000000000000000000000077e0e077770077700000000000000007ee000ee07777777e0000000000000000e077777007e0e07e0
|
|
0000000000000077e000000000000000000000000000007e07e7ee007e7e07e000000000000007e07e07e7ee0000007e0000000000000077ee0007e7e7e7ee7e
|
|
00000000000007e07e0000000000000000000000000007e7ee0007e7e007ee7e0000000000007e7ee7ee0007e00007e7e0000000000007e007e07e0000000007
|
|
0000000000007e7ee7e00000000000000000000000007e0007e07e007e7e0007e00000000007e0000007e07e7e007e007e00000000007e7e7e7ee7e000000077
|
|
000000000007e000007e000000000000000000000007e7e07e7ee7e7e007e07e7e000000007e7e00007e7ee007e7e7e7e7e000000007e0000000007e000007e7
|
|
00000000007e7e0007e7e0000000000000000000007e007ee00000007e7e7ee007e0000007e007e007e0007e7e000000007e0000007e7e00000007e7e0007e07
|
|
0000000007e007e07e007e00000000000000000007e7e7e07e000007e000007e7e7e00007e7e7e7e7e7e07e007e0000007e7e00007e007e000007e007e07e7e7
|
|
000000007e7e7e7ee7e7e7e000000000000000007e00007ee7e0007e7e0007e00007e007e00000000007ee7e7e7e00007e007e007e7e7e7e0007e7e7e7ee0007
|
|
00000007e00000000000007e0000000000000007e7e007e0007e07e007e07e7e007e7e7e7e000000007e00000007e007e7e7e7e7e0000007e07e00000007e077
|
|
0000007e7e000000000007e7e00000000000007e007e7e7e07e7ee7e7e7ee007e7e0000007e0000007e7e000007e7e7e000000007e00007e7ee7e000007e7ee7
|
|
000007e007e0000000007e007e000000000007e7e7e00007ee00000000007e7e007e00007e7e00007e007e0007e00007e0000007e7e007e000007e0007e00007
|
|
00007e7e7e7e00000007e7e7e7e0000000007e00007e007e07e000000007e007e7e7e007e007e007e7e7e7e07e7e007e7e00007e007e7e7e0007e7e07e7e0077
|
|
0007e0000007e000007e0000007e00000007e7e007e7e7e7ee7e0000007e7e7e00007e7e7e7e7e7e0000007ee007e7e007e007e7e7e00007e07e007ee007e7e7
|
|
007e7e00007e7e0007e7e00007e7e000007e007e7e0000000007e00007e00007e007e00000000007e00007e07e7e007e7e7e7e00007e007e7ee7e7e07e7e0007
|
|
07e007e007e007e07e007e007e007e0007e7e7e007e00000007e7e007e7e007e7e7e7e000000007e7e007e7ee007e7e0000007e007e7e7e00000007ee007e077
|
|
7e7e7e7e7e7e7e7ee7e7e7e7e7e7e7e07e00007e7e7e000007e007e7e007e7e0000007e0000007e007e7e0007e7e007e00007e7e7e00007e000007e07e7e7ee7
|
|
e000000000000000000000000000007ee7e007e00007e0007e7e7e007e7e007e00007e7e00007e7e7e007e07e007e7e7e007e00007e007e7e0007e7ee0000007
|
|
0e00000000000000000000000000000eeeee00ee0000ee000eeeeee00eeee00ee0000eeee0000eeeeee00e70ee00eeeeee00ee0000ee00eeee000eeeee000000
|
|
00e00000000000000000000000000000eeeee00ee0000ee000eeeeee00eeee00ee0000eeee0000eeeeee00e70ee00eeeeee00ee0000ee00eeee000eeeee00000
|
|
000e00000000000000000000000000000eeeee00ee0000ee000eeeeee00eeee00ee0000eeee0000eeeeee00e70ee00eeeeee00ee0000ee00eeee000eeeee0000
|
|
0000e00000000000000000000000000000eeeee00ee0000ee000eeeeee00eeee00ee0000eeee0000eeeeee00e70ee00eeeeee00ee0000ee00eeee000eeeee000
|
|
00000e00000000000000000000000000000eeeee00ee0000ee000eeeeee00eeee00ee0000eeee0000eeeeee00e70ee00eeeeee00ee0000ee00eeee000eeeee00
|
|
000000e00000000000000000000000000000eeeee00ee0000ee000eeeeee00eeee00ee0000eeee0000eeeeee00e70ee00eeeeee00ee0000ee00eeee000eeeee0
|
|
0000000e00000000000000000000000000000eeeee00ee0000ee000eeeeee00eeee00ee0000eeee0000eeeeee00e70ee00eeeeee00ee0000ee00eeee000eeeee
|
|
00000000e00000000000000000000000000000eeeee00ee0000ee000eeeeee00eeee00ee0000eeee0000eeeeee00e70ee00eeeeee00ee0000ee00eeee000eeee
|
|
000000000e00000000000000000000000000000eeeee00ee0000ee000eeeeee00eeee00ee0000eeee0000eeeeee00e70ee00eeeeee00ee0000ee00eeee000eee
|
|
0000000000e00000000000000000000000000000eeeee00ee0000ee000eeeeee00eeee00ee0000eeee0000eeeeee00e70ee00eeeeee00ee0000ee00eeee000ee
|
|
00000000000e00000000000000000000000000000eeeee00ee0000ee000eeeeee00eeee00ee0000eeee0000eeeeee00e70ee00eeeeee00ee0000ee00eeee000e
|
|
000000000000e00000000000000000000000000000eeeee00ee0000ee000eeeeee00eeee00ee0000eeee0000eeeeee00e70ee00eeeeee00ee0000ee00eeee000
|
|
0000000000000e00000000000000000000000000000eeeee00ee0000ee000eeeeee00eeee00ee0000eeee0000eeeeee00e70ee00eeeeee00ee0000ee00eeee00
|
|
00000000000000e00000000000000000000000000000eeeee00ee0000ee000eeeeee00eeee00ee0000eeee0000eeeeee00e70ee00eeeeee00ee0000ee00eeee0
|
|
000000000000000e00000000000000000000000000000eeeee00ee0000ee000eeeeee00eeee00ee0000eeee0000eeeeee00e70ee00eeeeee00ee0000ee00eeee
|
|
0000000000000000e00000000000000000000000000000eeeee00ee0000ee000eeeeee00eeee00ee0000eeee0000eeeeee00e70ee00eeeeee00ee0000ee00eee
|
|
0000000000000007e700000000000000000000000000070000e770e70070e70700000e77000e770e7007000e700700000e770e00e7700000e770e70070e7700e
|
|
00000000000000700e700000000000000000000000007e700700e00e77e00e0e7000700e70700e00e77e7070e77e7000700e0e7700e7000700e00e77e000e77e
|
|
00000000000007e770e700000000000000000000000700e77e77e77000e77e00e707e770e0e77e770000e0e00000e707e77e000e770e707e77e77000e707000e
|
|
0000000000007000e00e70000000000000000000007e7700000000e707000e770e0000e0e000000e7007e0e700070e00000e70700e00e0000000e7070e0e707e
|
|
000000000007e707e770e700000000000000000007000e700000070e0e70700e0e7007e0e7000070e770e00e707e0e700070e0e77e77e70000070e0e0e00e00e
|
|
0000000000700e0000e00e7000000000000000007e7070e700007e0e00e0e77e00e770e00e7007e000e0e770e00e00e707e0e00000000e70007e0e0e0e77e77e
|
|
0000000007e77e7007e770e7000000000000000700e0e00e70070e0e77e0000e7700e0e770e770e707e000e0e77e770e00e0e700000070e7070e0e0e0000000e
|
|
00000000700000e77000e00e700000000000007e77e0e770e77e0e0000e700700e77e000e000e00e00e707e000000e0e77e00e700007e00e0e0e0e0e7000007e
|
|
|