Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local shell = require("shell")
- local component = require("component")
- local function printErr(err)
- io.stderr:write(err.."\n")
- end
- local holo
- addresses = {}
- for address in component.list("hologram") do
- table.insert(addresses, address)
- print(#addresses .. ": " .. address)
- end
- if #addresses > 1 then
- io.write("Choose projector: ")
- local index
- repeat
- local input = string.gsub(require("term").read(), "\n", "")
- index = tonumber(input)
- if not (index and addresses[index]) then
- io.write("\nInvalid index!\nChoose projector: ")
- end
- until index and addresses[index]
- holo = component.proxy(addresses[index])
- end
- local args = shell.parse(...)
- if #args < 1 then
- printErr("Usage: hologram FILE")
- return
- end
- local file, reason = io.open(args[1], "r")
- if not file then
- printErr("Failed to open file: "..reason)
- return
- end
- local rawdata = file:read("*all")
- file:close()
- local data, reason = load("return "..rawdata)
- if not data then
- printErr("Failed loading model: "..reason)
- return
- end
- data = data()
- holo.clear()
- if data.scale then
- holo.setScale(data.scale)
- end
- if data.color1 then
- holo.setPaletteColor(1, data.color1)
- end
- if data.color2 then
- holo.setPaletteColor(2, data.color2)
- end
- if data.color3 then
- holo.setPaletteColor(3, data.color3)
- end
- if data.rotation then
- local d = data.rotation
- holo.setRotation(d[1], d[2], d[3], d[4])
- end
- if data.rotationSpeed then
- local d = data.rotationSpeed
- holo.setRotationSpeed(d[1], d[2], d[3], d[4])
- end
- if data.translation then
- local t = data.translation
- holo.setTranslation(t[1], t[2], t[3])
- end
- if not data.shapes then
- printErr("No shapes!")
- return
- end
- local function fill(minX,maxX, minZ,maxZ, minY,maxY, color)
- for w = minX,maxX do
- for d = minZ,maxZ do
- holo.fill(w,d,minY,maxY, color)
- end
- end
- end
- for k,v in pairs(data.shapes) do
- fill(v[1], v[2], v[3], v[4], v[5], v[6], v[7])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement