Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local CHANCE_TO_START_ALIVE = 500
- local BIRTH_LIMIT = 16
- local DEATH_LIMIT = 5
- local STEPS = 5
- local distance = 64
- local pointSize = 24
- function generateCave()
- x = GetRandom(4096)
- y = GetRandom(2048)
- local world = {}
- initializeWord(world)
- for i=1, STEPS do
- world = simulationStep(world)
- end
- for x=distance, 4096, distance do
- for y=distance, 2048, distance do
- if world[x / distance][y / distance] then
- AddPoint(x, y, pointSize)
- end
- end
- end
- FlushPoints()
- end
- function initializeWord(world)
- for x=1, 4096/distance do
- table.insert(world, {})
- for y=1, 2048/distance do
- if GetRandom(1000) < CHANCE_TO_START_ALIVE then
- table.insert(world[x], true)
- else
- table.insert(world[x], false)
- end
- end
- end
- end
- function simulationStep(world)
- world2 = {}
- for x=1, 4096/distance do
- table.insert(world2, {})
- for y=1, 2048/distance do
- local count = countNeigbours(world, x, y)
- if world[x][y] then
- if count < DEATH_LIMIT then
- table.insert(world2[x], false)
- else
- table.insert(world2[x], true)
- end
- else
- if count > BIRTH_LIMIT then
- table.insert(world2[x], true)
- else
- table.insert(world2[x], false)
- end
- end
- end
- end
- return world2
- end
- function countNeigbours(world, x, y)
- count = 0
- for dx=1, 3 do
- for dy=1, 3 do
- local x2 = x+dx-2
- local y2 = y+dy-2
- if x2 == 0 or x2 == 4096/distance+1 or y2 == 0 or y2 == 2048/distance+1 or world[x2][y2] then
- count = count + 1
- end
- end
- end
- return count
- end
- function onGameInit()
- MapGen = mgDrawn
- TemplateFilter = 0
- generateCave()
- end
- function onPreviewInit()
- onGameInit()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement