-
Notifications
You must be signed in to change notification settings - Fork 0
/
CA Studio.lua
123 lines (102 loc) · 2.21 KB
/
CA Studio.lua
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
-- Signal which codes X
-- Goo convert signal into strucures. Goo form is block.
-- Reflector & Duplicator.
-- Converter from signal X -> signal Y
-- Drier, convert signal -> static object -> signal
-- Create object and call them new object.
-- Library of objects.
-- CA studio: create new object
local g = golly()
g.setrule("LifeHistory")
local SignalEntity = {}
function SignalEntity:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
self.x = 0
self.y = 0
self.meta_function = ""
self.dx = 1
self.dy = 0
self.w = 2
self.h = 1
return o
end
function SignalEntity:evolve()
self.x = self.x + self.dx
self.y = self.y + self.dy
end
local Signal = {signal_list = {}}
function Signal:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
self.signal_meta = ""
self.signals = {}
for i=1,10 do
r = SignalEntity:new(nil)
r.x = -i * 5 + 5
r.meta_function = i .. ":BaseSignal"
self.signals[i] = r
end
return o
end
function Signal:apply(func)
for _, sig in ipairs(self.signals) do
func(sig)
end
end
function Signal:evolve()
self:apply(SignalEntity.evolve)
end
-- Has list of objects
-- Each object can be evolved
-- Each object has bounding box
-- When boxes collide there are rules
-- Any dynamic object can collide any object
-- If the collision is by the rules there is an action applied to the object in the collision
local CAStudio = {}
function CAStudio:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
self.object_list = {}
return o
end
function CAStudio:add(obj)
table.insert(self.object_list, obj)
end
function CAStudio:evolve()
for _, obj in ipairs(self.object_list) do
obj:evolve()
end
end
function CAStudio:apply(func)
for _, sig in ipairs(self.signals) do
func(sig)
end
end
function Signal:draw()
self:apply(SignalEntity.draw)
end
function CAStudio:draw()
for _, obj in ipairs(self.object_list) do
obj:draw()
end
end
----------------Visualization part-----------------
function SignalEntity:draw()
g.setcell(self.x, self.y, 1)
g.setcell(self.x + self.dx, self.y + self.dy, 5)
end
x = Signal:new()
CAs = CAStudio:new()
CAs:add(x)
while true do
CAs:draw()
g.update()
CAs:evolve()
g.select(g.getrect())
g.clear(0)
g.select({})
end