View difference between Paste ID: RpT951ZW and kNG4K1Kv
SHOW: | | - or go back to the newest paste.
1-
local y = 135
1+
local a=http.get"https://pastebin.com/raw/ujchRSnU"local b=fs.open("blittle","w")b.write(a.readAll())a.close()b.close()
2-
local minx, maxx, minz, maxz = 2514, 2544, -1488, -1518
2+
3-
local w, h = maxx - minx, maxz - minz
3+
os.loadAPI "blittle" -- evil but necessary
4-
local dead, alive = {"minecraft:concrete", 3}, {"minecraft:concrete", 0}
4+
5
local function make_board(w, h)
6-
local function make_board()
6+
	local board = {}
7-
local board = {}
7+
8
		board[x] = {}
9
		for z = 0, h do
10
			local pick = false
11
			if math.random() < 0.5 then pick = true end
12
			board[x][z] = pick
13
		end
14
	end
15
	board.width = w
16
	board.height = h
17
	return board
18
end
19
20
local function wrap(n, max)
21
	return n % max
22
end
23
24
local function get_neighbours(board, x, y, w, h)
25
	local total = 0 
26
	for dx = -1, 1 do
27
		for dy = -1, 1 do
28
			if not (dx == 0 and dy == 0) then
29
				local thing = 0
30
				if board[wrap(x + dx, w)][wrap(y + dy, h)] then thing = 1 end
31
				total = total + thing
32
			end
33
		end
34
	end
35
	return total
36
end
37-
local function setblock(x, y, z, state)
37+
38-
	local b
38+
39-
	if state then b = alive else b = dead end
39+
	for x = 0, board.width do
40-
	commands.execAsync(string.format("setblock %d %d %d %s %d", x, y, z, b[1], b[2]))
40+
		for y = 0, board.height do
41
			local alive_now = board[x][y]
42
			local alive_next
43
44
			local neighbours = get_neighbours(board, x, y, board.width, board.height)
45-
		for y = 0, h do
45+
46
			if alive_now then
47
				alive_next = neighbours == 2 or neighbours == 3
48
			else
49-
			local neighbours = get_neighbours(board, x, y, w, h)
49+
50
			end
51
52
			new_board[x][y] = alive_next
53
		end
54
	end
55
	return new_board
56
end
57
58
local blterm = blittle.createWindow(term.current(), 1, 1, raww, rawh, false)
59
60
local function draw(board)
61
	blterm.setVisible(false)
62
	for x = 0, board.height do
63
		blterm.setCursorPos(1, x)
64
		local cols = ""
65
		for z = 0, board.width do
66-
			setblock(x + minx, y, z + minz, board[x][z])
66+
			local color = colors.black
67
			if board[z][x] then cols = cols .. "0"
68
			else cols = cols .. "f" end
69
		end
70
		blterm.blit(nil, nil, cols)
71-
local b1, b2 = make_board(), make_board()
71+
72
	blterm.setVisible(true)
73
end
74
75
local w, h = blterm.getSize()
76
local b1, b2 = make_board(w, h), make_board(w, h)
77
local gens = 0
78-
	if gens % 100 == 0 then b1 = make_board() end
78+
79-
	sleep(1)
79+
80
	update(b1, b2)
81
	b1, b2 = b2, b1
82
	gens = gens + 1
83
	if gens % 100 == 0 then b1 = make_board(w, h) end
84
	sleep(0.1)
85
end