Skip to content

Instantly share code, notes, and snippets.

@Inari-Whitebear
Last active May 17, 2016 09:27
Show Gist options
  • Save Inari-Whitebear/b50f6df5509303ffbad1df31c8996edd to your computer and use it in GitHub Desktop.
Save Inari-Whitebear/b50f6df5509303ffbad1df31c8996edd to your computer and use it in GitHub Desktop.
local hololib = {}
local component = require("component")
local os = require("os")
if component.hologram == nil then
error("Requires hologram projector")
end
local DIM_X = 48
local DIM_Y = 32
local DIM_Z = 48
hololib.device = component.hologram
hololib.data = ""
local function dataInit()
hololib.data = string.rep(string.char(0), DIM_X*DIM_Y*DIM_Z)
end
dataInit()
local function coordsToIndex(x, y, z)
return ((y - 1) + DIM_Y * (z - 1) + (DIM_Z * DIM_Y) * (x - 1)) + 1
end
function hololib:set(x, y, z, n)
local index = coordsToIndex(x, y, z)
self.data = self.data:sub(1, index - 1) .. string.char(n) .. self.data:sub(index + 1)
end
function hololib:get(x, y, z, n)
return string.byte(self.data, coordsToIndex(x, y, z))
end
function hololib:readFromDevice()
for x = 1, DIM_X, 1 do
for y = 1, DIM_Y, 1 do
for z = 1, DIM_Z, 1 do
self:set(x, y, z, self.device.get(x, y, z))
end
os.sleep(0)
end
end
end
function hololib:flush()
self.device.setRaw(self.data)
end
return hololib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment