Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
18 May, 2013, 15:23:04 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1]   Go Down
  Print  
Author Topic: GOLua -  (Read 249 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
linuxgeek96
LV3 Member (Next: 100)
***
Offline Offline

Last Login: 16 May, 2013, 23:05:36
Date Registered: 17 October, 2011, 18:15:24
Location: WLHS
Posts: 96


Topic starter
Total Post Ratings: +3

View Profile WWW
« on: 09 April, 2012, 14:58:48 »
0

Hi,

Since some people wanted my GOL code, here it is!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
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!
Logged

DJ Omnimaga
Retired Omnimaga founder (Site issues must be PM'ed to Netham45, Eeems, Shmibs, Deep Thought and AngelFish, not me.)
Editor
LV15 Omnimagician (Next: --)
*
Offline Offline

Gender: Male
Last Login: Today at 10:41:03
Date Registered: 25 August, 2008, 07:00:21
Location: Québec (Canada)
Posts: 50196


Total Post Ratings: +2611

View Profile WWW
« Reply #1 on: 18 April, 2012, 06:23:12 »
0

Could you explain in a bit more detail what this do? Is it a game, a new Nspire language, some tool?
Logged

Retired 83+ coder, Omnimaga/TIMGUL founder. Now doing power metal music (formerly did electronica)

Follow me on Bandcamp|Facebook|Reverbnation|Youtube|Twitter|Myspace
Chockosta
LV6 Super Member (Next: 500)
******
Offline Offline

Gender: Male
Last Login: 16 May, 2013, 19:52:18
Date Registered: 03 June, 2011, 20:14:17
Location: France
Posts: 440


Total Post Ratings: +159

View Profile
« Reply #2 on: 18 April, 2012, 11:49:39 »
0

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
Logged

Chockosta (Loic Pujet) - Sorry for my poor English...
Look at my projects :
in C code : Periodic table, Space invaders, Fall, Snake, Minesweeper, nCraft (WIP)
in Lua : Snake, Space invaders, Bobby Carrot, Minesweeper, Mazes 3D, nSpaint, FreeCell, Tiny3D-Viewer, CubeField, Gravity Guy
linuxgeek96
LV3 Member (Next: 100)
***
Offline Offline

Last Login: 16 May, 2013, 23:05:36
Date Registered: 17 October, 2011, 18:15:24
Location: WLHS
Posts: 96


Topic starter
Total Post Ratings: +3

View Profile WWW
« Reply #3 on: 18 April, 2012, 13:17:52 »
0

oops. I didn't see that before I wrote it. However, this has a POV feature, which I don't believe Kemp's has.
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.287 seconds with 30 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.