summaryrefslogtreecommitdiff
path: root/beescroll.lua
blob: 64be07627ced3fcb522bf9c29c91d499a02bb70e (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
124
125
126
127
128
129
130
131
132
133
134
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 write_str(m,s,slow)
	local W,H = m.getSize()
	for i = 1,#s do
		m.write(s:sub(i,i))
		if slow then
			os.sleep(0.1)
		end
		if (m.getCursorPos()) == W then
			m.scroll(1)
			m.setCursorPos(1,H)
		end
	end
end

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

local norm_color = colors.gray

local urgent = { "URGENT", "WARNING", "ALERT", "CRITICAL", "BREAKING" }
local orgs = {"Council", "Committee", "Board", "Division", "Bureau", "Team", "Task Force", "Secretariat" }
local orgtype = { "Executive", "Leadership", "Management", "Control", "Command", "Planning" }
local function pretitle()
	local out = ""
	while math.random() < 0.5 do out = choice{"Acting","Acting","Provisional","Provisional","Provisional","Strategic"} .. " " .. out end
	return out
end

local function beecount()
	if math.random() < 0.4 then return {colors.yellow, "all bees ", norm_color} end
	local n = ("%4d"):format(math.random(9999))
	return {colors.yellow, 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()
	local council = {choice{colors.red, colors.blue, colors.green}, pretitle(), choice(orgtype), " ", choice(orgs), norm_color}
	return {
		colors.red, choice(urgent), norm_color, ": ",
		choice {
		-- the council has condemned all bees for [being/having been] boiled [illegally/without a permit/behind schedule]
			{ "The ", council, " has 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
			{ "The ", council, " has 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
			{ "The ", council, " has scheduled ", beecount(), "to be ", colors.brown, choice(verbs),
				norm_color, " by ", timeframe() },
		-- 9998 bees were exploded [mistakenly/in error/by accident/by our enemies]. the council has [ordered/decreed/decided] that 1234 bees will be boiled [instead/as compensation/as well]
			{ beecount(), "were ", colors.magenta, choice(verbs), norm_color, " ",
				choice{"mistakenly","in error","by accident","by our enemies"},
				". The ", council, " has ", choice{"ordered","decreed","decided"}, " that ",
				beecount(), "will be ", colors.pink, choice(verbs), norm_color, " ",
				choice{"instead","as compensation","as well","or else"}},

		}, norm_color, "." }
	end



local function regular_item()
	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

local function some_item()
	if math.random()<0.05 then return news_item() else return regular_item() end
end

for _ = 1,H do
	m.scroll(1)
	m.setCursorPos(1,H)
	f_write(m,some_item(), false)
end
while true do
	m.scroll(1)
	m.setCursorPos(1,H)
	f_write(m, some_item(), false)
	os.sleep(math.random(5,100)/100)

end