Author Topic: GOLua  (Read 1511 times)

0 Members and 1 Guest are viewing this topic.

Offline linuxgeek96

  • LV3 Member (Next: 100)
  • ***
  • Posts: 99
  • Rating: +4/-0
  • ( ͡° ͜ʖ ͡°)
    • View Profile
    • Personal Site
GOLua
« on: April 09, 2012, 08:58:48 am »
Hi,

Since some people wanted my GOL code, here it is!
Code: [Select]
function on.paint(gc)
gc:setColorRGB(0,0,64)
gc:fillRect(0,0,318,212)
if j==nil then
j=8
create("bla")
end
if c=="5" then
create("bla")
c=""
elseif c=="u" then
elseif c=="p" then
pause=1
elseif c=="c" then
pause=0
elseif c=="+" then
j=j-1
c="5"
elseif c=="-" then
j=j+1
c="5"
else
for x=1,xlen do
local xs={}
if x==1 then
xs={xlen,1,2}
elseif x==xlen then
xs={xlen-1,xlen,1}
else
xs={x-1,x,x+1}
end
for y=1,ylen do
local ys={}
local n=0
if y==1 then
ys={ylen,1,2}
elseif y==ylen then
ys={ylen-1,ylen,1}
else
ys={y-1,y,y+1}
end
n=color[xs[1]][ys[1]]+color[xs[1]][ys[2]]+color[xs[1]][ys[3]]+color[xs[2]][ys[1]]+color[xs[2]][ys[3]]+color[xs[3]][ys[1]]+color[xs[3]][ys[2]]+color[xs[3]][ys[3]]
if n==3 then
buffer[x][y]=1
elseif n < 2 or n > 3 then
buffer[x][y]=0
end
end
end
end
for x=1,xlen do
for y=1,ylen do
local cell=buffer[x][y]
local lell=cell-color[x][y]
color[x][y]=cell
if lell==1 then
gc:setColorRGB(0,255,0)
elseif cell==1 and lell==0 then
gc:setColorRGB(0,128,0)
elseif lell==-1 then
gc:setColorRGB(96,32,16)
elseif cell==0 and lell==0 then
gc:setColorRGB(0,0,0)
end
gc:fillArc(x*j-0.5*j,y*j-0.5*j,0.75*j,0.75*j,0,360)
end
end
if pause==1 then
c="p"
end
--gc:drawString(debugStr,1,1,"top")
end
function on.charIn(ch)
c=ch
platform.window:invalidate()
end
function on.timer()
platform.window:invalidate()
end
function on.mouseDown(x,y)
--j=math.floor(x/318*11)
--c="5"
changePixel(x,y)
end
function on.mouseMove(x,y)
if pause==1 then
changePixel(x,y)
end
end
function changePixel(x,y)
if math.floor(x/j)>0 and math.floor(y/j)>0 then
if buffer[math.floor(x/j)][math.floor(y/j)]==1 then
buffer[math.floor(x/j)][math.floor(y/j)]=0
else
buffer[math.floor(x/j)][math.floor(y/j)]=1
end
platform.window:invalidate()
end
end
function on.save()
data = {buffer, color, j, data}
return data
end
function on.restore(data)
buffer = data[1]
color = data[2]
j = data[3]
menu = data[4]
timer.start(1)
pause=0
w=316
h=210
xlen=math.floor(w/j)
ylen=math.floor(h/j)
toolpalette.register(menu)
--create("reset")
end
function create(mode)
t=1
timer.start(t)
pause=0
w=316
h=210
xlen=math.floor(w/j)
ylen=math.floor(h/j)
buffer={}
color={}
for x=1,xlen do
buffer[x]={}
color[x]={}
for y=1,ylen do
if mode=="clear" then
color[x][y]=0
buffer[x][y]=0
elseif math.random()>0.5 then
color[x][y]=1
buffer[x][y]=1
else
color[x][y]=0
buffer[x][y]=0
end
end
end
reloadMenu()
debugStr=mode
end
function decTick()
t=t+0.02
timer.stop()
timer.start(t)
reloadMenu()
end
function incTick()
t=t-0.02
timer.stop()
timer.start(t)
reloadMenu()
if t<=1/15 then
t=1/15
end
end
function reset()
create("reset")
end
function reloadMenu()
menu={{"Functions",{"Reset",reset},{"Clear",clear},"-",{"t="..t,clear},{"Increase tick speed",incTick},{"Decrease tick speed",decTick}}}
toolpalette.register(menu)
end
function clear()
create("clear")
end
README:
Press p to pause and draw using mouseover (buggy), after which c will set it in mouse click draw mode, and o will resume. Press + or - to increase or decrease matrix size. Some functions are on the menu. Enjoy!
Questions and comments are welcome!

Online DJ Omnimaga

  • Former TI programmer
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55845
  • Rating: +3151/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • DJ Omnimaga Music
Re: GOLua
« Reply #1 on: April 18, 2012, 12:23:12 am »
Could you explain in a bit more detail what this do? Is it a game, a new Nspire language, some tool?
In case you are wondering where I went, I left Omni back in 2015 to form CodeWalrus due to various reasons explained back then, but I stopped calc dev in 2016 and am now mostly active on the CW Discord server at https://discord.gg/cuZcfcF



Official Website |T-Shirt store | Reverbnation | Facebook | Youtube | Twitter | Spotify

Offline Chockosta

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 447
  • Rating: +169/-6
    • View Profile
Re: GOLua
« Reply #2 on: April 18, 2012, 05:49:39 am »
It's a port af the Conway's game of life

BTW, there was already one by Andy Kemp at http://tiplanet.org/forum/archives_voir.php?id=3563

Offline linuxgeek96

  • LV3 Member (Next: 100)
  • ***
  • Posts: 99
  • Rating: +4/-0
  • ( ͡° ͜ʖ ͡°)
    • View Profile
    • Personal Site
Re: GOLua
« Reply #3 on: April 18, 2012, 07:17:52 am »
oops. I didn't see that before I wrote it. However, this has a POV feature, which I don't believe Kemp's has.