Skip to content

Instantly share code, notes, and snippets.

@John2143
Created November 1, 2020 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save John2143/d83192a5c6ca3b3c604dc6fc30d3a3b6 to your computer and use it in GitHub Desktop.
Save John2143/d83192a5c6ca3b3c604dc6fc30d3a3b6 to your computer and use it in GitHub Desktop.
-- This program allows for multiple holo projectors to use the same computer and wire network.
local texts = {
["36ad5972-6d20-4fb3-bf32-b64492248485"] = "Launchpad ",
["a875bda6-cee8-4c4e-8b4a-1aad84eb314f"] = "Automation ",
}
local component = require("component")
local keyboard = require("keyboard")
local glyphs = {
["a"]=[[
XXXXX
X X
XXXXX
X X
X X
]],
["b"]=[[
XXXX
X X
XXXX
X X
XXXX
]],
["c"]=[[
XXXXX
X
X
X
XXXXX
]],
["d"]=[[
XXXX
X X
X X
X X
XXXX
]],
["e"]=[[
XXXXX
X
XXXX
X
XXXXX
]],
["f"]=[[
XXXXX
X
XXXX
X
X
]],
["g"]=[[
XXXXX
X
X XXX
X X
XXXXX
]],
["h"]=[[
X X
X X
XXXXX
X X
X X
]],
["i"]=[[
XXX
X
X
X
XXX
]],
["j"]=[[
X
X
X
X X
XXXXX
]],
["k"]=[[
X X
X X
XXX
X X
X X
]],
["l"]=[[
X
X
X
X
XXXXX
]],
["m"]=[[
X X
XX XX
X X X
X X
X X
]],
["n"]=[[
X X
XX X
X X X
X XX
X X
]],
["o"]=[[
XXXXX
X X
X X
X X
XXXXX
]],
["p"]=[[
XXXXX
X X
XXXXX
X
X
]],
["q"]=[[
XXXXX
X X
X X
X X
XXX X
]],
["r"]=[[
XXXXX
X X
XXXX
X X
X X
]],
["s"]=[[
XXXXX
X
XXXXX
X
XXXXX
]],
["t"]=[[
XXXXX
X
X
X
X
]],
["u"]=[[
X X
X X
X X
X X
XXXXX
]],
["v"]=[[
X X
X X
X X
X X
X
]],
["w"]=[[
X X
X X
X X X
X X X
X X
]],
["x"]=[[
X X
X X
X
X X
X X
]],
["y"]=[[
X X
X X
XXX
X
X
]],
["z"]=[[
XXXXX
X
XXX
X
XXXXX
]],
["0"]=[[
XXX
X X
X X X
X X
XXX
]],
["1"]=[[
XX
X X
X
X
X
]],
["2"]=[[
XXXX
X
X
X
XXXXX
]],
["3"]=[[
XXXX
X
XXX
X
XXXX
]],
["4"]=[[
X X
X X
XXXXX
X
X
]],
["5"]=[[
XXXXX
X
XXXX
X
XXXX
]],
["6"]=[[
XXX
X
XXXX
X X
XXX
]],
["7"]=[[
XXXXX
X
XXX
X
X
]],
["8"]=[[
XXX
X X
XXX
X X
XXX
]],
["9"]=[[
XXX
X X
XXXX
X
XXX
]],
[" "]=[[
]],
["."]=[[
X
]],
[","]=[[
X
X
]],
[";"]=[[
X
X
X
]],
["-"]=[[
XXX
]],
["+"]=[[
X
XXX
X
]],
["*"]=[[
X X
X
X X
]],
["/"]=[[
X
X
X
X
X
]],
["\\"]=[[
X
X
X
X
X
]],
["_"]=[[
XXXXX
]],
["!"]=[[
X
X
X
X
]],
["?"]=[[
XXX
X
XX
X
]],
["("]=[[
X
X
X
X
X
]],
[")"]=[[
X
X
X
X
X
]],
}
-- Generate one big string that represents the concatenated glyphs for the provided text.
local function getValue(text)
local value = ""
for row = 1, 5 do
for col = 1, #text do
local char = string.sub(text:lower(), col, col)
local glyph = glyphs[char]
if glyph then
local s = 0
for _ = 2, row do
s = string.find(glyph, "\n", s + 1, true)
if not s then
break
end
end
if s then
local line = string.sub(glyph, s + 1, (string.find(glyph, "\n", s + 1, true) or 0) - 1)
value = value .. line .. " "
end
end
end
value = value .. "\n"
end
return value
end
local function createBMData(value)
local bm = {}
for token in value:gmatch("([^\r\n]*)") do
if token ~= "" then
table.insert(bm, token)
end
end
local h,w = #bm,#bm[1]
local sx, sy = math.max(0,(16*3-w)/2), 2*16-h-1
local z = 16*3/2
return bm, h, w, sx, sy, z
end
local function updateHolo(hologram, i, bm, h, w, sx, sy, z)
local function col(n)
return (n - 1 + i) % w + 1
end
for i=1, math.min(16*3,w) do
local x = sx + i
local i = col(i)
for j=1, h do
local y = sy + j-1
if bm[1+h-j]:sub(i, i) ~= " " then
hologram.set(x, y, z, 1)
else
hologram.set(x, y, z, 0)
end
if keyboard.isKeyDown(keyboard.keys.w) and keyboard.isControlDown() then
hologram.clear()
os.exit()
end
end
end
end
local function unpack (t, i)
i = i or 1
if t[i] ~= nil then
return t[i], unpack(t, i + 1)
end
end
local mapped = {}
for id, text in pairs(texts) do
local v = getValue(text)
local bms = {createBMData(v)}
local holo = component.proxy(id)
holo.setPaletteColor(1, 0x00CCFF)
holo.clear()
print("Multiplexing: ", id, text)
table.insert(mapped, {holo, bms})
end
for i = 1, math.huge do
os.sleep(.1)
for _, map in pairs(mapped) do
local holo = map[1]
local bms = map[2]
updateHolo(holo, i*3, unpack(bms))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment