summaryrefslogtreecommitdiff
path: root/ywang/nodes/(1991,19,8251).lua
blob: 740144a63f7ee2971e34616810d3d1c166c68d09 (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
local formats = {".%d", "+%d", "%d\t", "\t%d",  "%d ", " %d", "%d\n", "\n%d", "-%d", "%d."}
local len = #formats*10

local function color(num)
  return math.fmod(num*67+101, 255) + math.fmod(num*97+109, 255) + math.fmod(num*73+127, 255)
end

if not disco then
  disco = 0
end
if not atc_id then
  return
end
if event.type == "train" then
  if not atc_id then return end
  atc_send("B0")
  disco = 0
end
if event.type == "train" or event.type == "schedule" then
  local line = get_line()
  if not line or line == "" or (line:len() == 2 and tonumber(line)) then
    local digit, fmt, str
    for _ = 1, 10 do
      digit = math.floor(disco/#formats)
      fmt = formats[disco%#formats+1]
      str = fmt:format(digit)
      disco = (disco+1)%len
      if color(tonumber(str)) <= 512 then
        break
      end
    end
    set_line(str)
    schedule_in(5)
  end
end