Skip to content

Instantly share code, notes, and snippets.

@Seniorendi

Seniorendi/.lua Secret

Created Apr 27, 2021
Embed
What would you like to do?
AR Controller draw .nfp api
local arg = {...}
color_map = {}
table.insert(color_map, 0xf0f0f0)
table.insert(color_map, 0xf2b233)
table.insert(color_map, 0xe57fd8)
table.insert(color_map, 0x99b2f2)
table.insert(color_map, 0xdede6c)
table.insert(color_map, 0x7fcc19)
table.insert(color_map, 0xf2b2cc)
table.insert(color_map, 0x4c4c4c)
table.insert(color_map, 0x999999)
table.insert(color_map, 0x4c99b2)
table.insert(color_map, 0xb266e5)
table.insert(color_map, 0x3366cc)
table.insert(color_map, 0x7f664c)
table.insert(color_map, 0x57a64e)
table.insert(color_map, 0xcc4c4c)
table.insert(color_map, 0x111111)
controller = peripheral.find("arController")
if controller == nil then
error("Can't find AR Controller")
end
if #arg < 3 then
error("Required arguments: filePath (string), x (int), y (int)")
end
filePath = arg[1]
if not fs.exists(filePath) then
error("File not found")
end
fileHeight = 0
fileWidth = 0
file = fs.open(filePath, "r")
repeat
line = file.readLine()
fileHeight = fileHeight + 1
if line ~= nil and #line > fileWidth then
fileWidth = #line
end
until line == nil
file.close()
x = arg[2]
y = arg[3]
if #arg < 5 then
uw = 5
uh = 7
else
uw = math.ceil(arg[4] / fileWidth)
uh = math.ceil(arg[5] / fileHeight)
end
file = fs.open(filePath, "r")
c = file.read()
xd = 0
yd = 0
repeat
local i = tonumber(c, 16)
if i ~= nil and i < 16 and i >= 0 then
local col = color_map[i+1]
controller.fill(x + xd, y + yd, x + xd + uw, y + yd + uh, col)
end
c = file.read()
if c == "\n" then
yd = yd + uh
xd = 0
c = file.read()
else
xd = xd + uw
end
until c == nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment