Skip to content

Commit

Permalink
CAModels replaced by Models. #12.
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-andrade-inpe committed Feb 5, 2016
1 parent 1b4b215 commit df52fc7
Show file tree
Hide file tree
Showing 41 changed files with 835 additions and 335 deletions.
45 changes: 0 additions & 45 deletions examples/excitable.lua

This file was deleted.

36 changes: 0 additions & 36 deletions examples/growth.lua

This file was deleted.

36 changes: 0 additions & 36 deletions examples/oscillator.lua

This file was deleted.

37 changes: 0 additions & 37 deletions examples/parasit.lua

This file was deleted.

36 changes: 0 additions & 36 deletions examples/parity.lua

This file was deleted.

39 changes: 0 additions & 39 deletions examples/snow.lua

This file was deleted.

8 changes: 8 additions & 0 deletions load.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ files = {
"CellularAutomataModel.lua",
"Utils.lua",
"Anneal.lua",
"DaisyWorld.lua",
"Excitable.lua",
"Fire.lua",
"Growth.lua",
"LifePatterns.lua",
"Life.lua",
"Oscillator.lua",
"Parasit.lua",
"Parity.lua",
"Snow.lua",
"SolidDiffusion.lua",
"Wolfram.lua"
}

69 changes: 43 additions & 26 deletions lua/Anneal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,52 @@
-- @arg data.dim The x and y dimensions of space.
-- @arg data.finalTime A number with the final time of the simulation.
-- @image anneal.bmp
Anneal = CellularAutomataModel{
Anneal = Model{
finalTime = 100,
dim = 80,
init = function(cell)
if Random():number() > 0.5 then
cell.state = "L"
else
cell.state = "R"
end
end,
changes = function(cell)
local alive = countNeighbors(cell, "L")
init = function(model)
model.cell = Cell{
init = function(cell)
if Random():number() > 0.5 then
cell.state = "L"
else
cell.state = "R"
end
end,
execute = function(cell)
local alive = countNeighbors(cell, "L")

if cell.state == "L" then alive = alive + 1 end
if cell.state == "L" then alive = alive + 1 end

if alive <= 3 then
cell.state = "R"
elseif alive >= 6 then
cell.state = "L"
elseif alive == 4 then
cell.state = "L"
elseif alive == 5 then
cell.state = "R"
end
end,
map = {
select = "state",
value = {"L", "R"},
color = {"black", "white"}
}
if alive <= 3 then
cell.state = "R"
elseif alive >= 6 then
cell.state = "L"
elseif alive == 4 then
cell.state = "L"
elseif alive == 5 then
cell.state = "R"
end
end
}

model.cs = CellularSpace{
xdim = model.dim,
instance = model.cell
}

model.cs:createNeighborhood()

model.map = Map{
target = model.cs,
select = "state",
value = {"L", "R"},
color = {"black", "white"}
}

model.timer = Timer{
Event{action = model.cs}
}
end
}

2 changes: 2 additions & 0 deletions lua/CellularAutomataModel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
-- "color" & A table with the colors for the respective values.
-- @arg data.init A function that describes how a Cell will be initialized.
-- @arg data.changes A function that describes how each Cell is updated.
-- @arg data.space An optional function to create space. It gets the
-- model as argument and must return a CellularSpace.
-- @usage import("ca")
--
-- Anneal = CellularAutomataModel{
Expand Down
Loading

0 comments on commit df52fc7

Please sign in to comment.