-
-
Save LizzyTrickster/ffcf09300b88d365d97a7ada1fa9c3f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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