summaryrefslogtreecommitdiff
path: root/beescroll.lua
blob: 0481c01e906ee46cd8b0ed628b072ca85ef65b45 (plain)
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
local m = peripheral.find"monitor"
m.setTextScale(0.5)

local W,H = m.getSize()

local function read_lines(fname)
	local out = {}
	local fp = assert(fs.open(fname,"r"))
	repeat
		local line = fp.readLine()
		table.insert(out, line)
	until not line
	fp.close()
	return out
end

local cities = read_lines("/cities.txt")
local verbs = read_lines("/verbs.txt")

local function choice(list)
	return list[math.random(#list)]
end
local function maybe(list, prob)
	prob = prob or 0.5
	if math.random() < prob then
		return choice(list) .. " "
	else
		return ""
	end
end

local function slow_write(m,s)
	for i = 1,#s do
		m.write(s:sub(i,i))
		os.sleep(0.1)
	end
end

local function f_write(mon, tab, fn)
	for _,val in ipairs(tab) do
		if type(val) == "string" then fn(mon, val)
		elseif type(val) == "number" then mon.setTextColor(val)
		else f_write(mon, val, fn)
		end
	end
end

local function f_write_fast(mon, tab)
	f_write(mon, tab, function(mon, str) mon.write(str) end)
end
local function f_write_slow(mon, tab)
	f_write(mon, tab, function(mon, str) slow_write(mon, str) end)
end


local norm_color = colors.gray

local urgent = { "URGENT", "WARNING", "ALERT", "CRITICAL", "BREAKING" }
local orgs = {"Council", "Committee", "Board" }
local orgtype = { "Executive", "Leadership", "Management" }
local function pretitle()
	local out = ""
	while math.random() < 0.25 do out = choice{"Acting","Provisional","Provisional"} .. " " .. out end
	return out
end

local function beecount()
	if math.random() < 0.4 then return {"all bees ", norm_color} end
	local n = ("%4d"):format(math.random(9999))
	return {n, " bees ", norm_color}
end

local function timeframe()
	return choice {
		"the end of the day",
		("%02d:00 tomorrow"):format(math.random(23)),
		"next "..choice{"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"},
	}
end

local function news_item()
	return {
		"    ", colors.red, choice(urgent), norm_color, ": ",
		"The ", choice{colors.red, colors.blue, colors.green}, pretitle(), choice(orgtype), " ", choice(orgs),
		norm_color, " has ", choice {
		-- the council has condemned all bees for [being/having been] boiled [illegally/without a permit/behind schedule]
			{ "condemned ", beecount(), "for ", choice{"being","having been"}, " ", colors.blue, choice(verbs),
				norm_color, choice{"illegally","without a permit","behind schedule"} },
		-- the council has decreed that 1234 bees shall be skewed by next tuesday
			{ "decreed that ", beecount(), "shall be ", colors.orange, choice(verbs),
				norm_color, " by ", timeframe() },
		-- the council has scheduled 9998 bees to be translated by next thursday
			{ "scheduled ", beecount(), "to be ", colors.brown, choice(verbs),
				norm_color, " by ", timeframe() },
		}, norm_color, "." }
	end



local function make_entry()
	return {
		choice{colors.yellow, colors.red, colors.cyan},
		string.format("%5d",math.random(0,99999)),
		norm_color, " bees ", choice{"have been ","were "},
		choice{colors.lime, colors.lightBlue, colors.pink},
		choice(verbs),
		norm_color, " in ",
		choice{colors.orange, colors.yellow, colors.purple},
		choice(cities),
		norm_color, "."}
end
for _ = 1,H do
	m.scroll(1)
	m.setCursorPos(1,H)
	f_write_fast(m,make_entry())
end
while true do
	m.scroll(1)
	m.setCursorPos(1,H)
	f_write_slow(m, news_item())
	os.sleep(math.random(5,100)/10)

end