Last active
February 13, 2022 22:26
-
-
Save oatmealine/ac1b173cc4b72d97e010e422e869fa0a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
-- constants | |
SCREEN_WIDTH = 24 | |
SCREEN_HEIGHT = 24 | |
sw, sh = SCREEN_WIDTH, SCREEN_HEIGHT | |
-- timer | |
local ticks = 0 | |
local time = 0 | |
function tick() | |
ticks = ticks + 1 | |
end | |
function render(delta) | |
time = (ticks + delta) / 20 | |
end | |
-- set position | |
local monitorPos = data.load('monitorPos') | |
model.NO_PARENT.screen.setEnabled(false) | |
ping.setpos = function(p) | |
local pos = {math.floor(p.x) + 0.5, math.floor(p.y + 0.5), math.floor(p.z) + 0.5} | |
model.NO_PARENT.screen.setEnabled(true) | |
model.NO_PARENT.screen.setPos(vectors.worldToPart(pos)) | |
model.NO_PARENT.screen.setRot({0, math.floor((-p.w or 0) / 90) * 90, 0}) | |
end | |
if monitorPos then ping.setpos(monitorPos) end | |
action_wheel.SLOT_1.setTitle('place down pc') | |
action_wheel.SLOT_1.setFunction(function() | |
monitorPos = player.getPos() | |
monitorPos = vectors.of({monitorPos.x, monitorPos.y, monitorPos.z, player.getRot().y}) | |
ping.setpos(monitorPos) | |
data.save('monitorPos', monitorPos) | |
end) | |
-- render misc | |
if model.NO_PARENT.screen.block.setLight then | |
function world_render() | |
if monitorPos then | |
local block, sky = world.getLightLevel(monitorPos), world.getSkyLightLevel(monitorPos) | |
model.NO_PARENT.screen.block.setLight({block, sky}) | |
end | |
end | |
end | |
-- util | |
local t = {} | |
local c = model.NO_PARENT.screen.pixels.getChildren() | |
function xyToIndex(x, y) | |
return ((x - 1) % sw) + (y - 1) * sw + 1 | |
end | |
function getPixel(x, y) | |
local i = xyToIndex(x, y) | |
return c[tostring(i)] | |
end | |
-- state management & encoding | |
-- from here on out chunk = color | |
INT_SIZE = 8 - 1 -- string w/ one bit reserved to make figura's backend happy | |
PALETTE = { -- MUST BE POWER OF 2 SIZE (update colChunkSize accordingly) | |
{0, 0, 0}, {1, 1, 1}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {1, 1, 0}, {1, 0, 1}, {0, 1, 1} | |
} | |
CHUNK_SIZE = 3 -- wtf (i tried to make this dynamic, blame math.log) | |
CHUNKS_PER_INT = math.floor(INT_SIZE / CHUNK_SIZE) | |
--- returns a mask with however many bits specified set to 1 | |
--- 1 -> 10000 | |
--- 2 -> 11000 | |
--- 3 -> 11100 | |
--- etc... | |
local function createMask(size) | |
local mask = 0 | |
for i = 1, size do | |
mask = bit32.bor(bit32.lshift(mask, 1), 1) | |
end | |
return mask | |
end | |
CHUNK_MASK = createMask(CHUNK_SIZE) | |
function toBits(num, size) | |
size = size or INT_SIZE | |
local t = {} -- will contain the bits | |
for i = 1, size do | |
if bit32.band(num, bit32.lshift(1, i - 1)) ~= 0 then | |
table.insert(t, '1') | |
else | |
table.insert(t, '0') | |
end | |
end | |
return table.concat(t) | |
end | |
--- given a table of palette-sized color ints, encodes it into a minimal table of integers | |
--- | |
--- for the sake of simplicity, this function | |
--- does not support cases where CHUNK_SIZE > INT_SIZE | |
--- | |
---@param s number[] | |
---@return number[] | |
function encodeData(s) | |
local ints = {} | |
local stackNumber = 0 | |
local stackSize = 0 | |
for _, v in ipairs(s) do | |
assert(stackSize <= INT_SIZE, 'stack number overflown! is CHUNK_SIZE bigger than INT_SIZE?') | |
stackSize = stackSize + CHUNK_SIZE | |
if stackSize > INT_SIZE then -- uh oh! our stack size is about to become bigger than its allowed to! | |
local shaveOff = stackSize - INT_SIZE -- we need to shave off this many bits to make it fit | |
if shaveOff == 0 or shaveOff == CHUNK_SIZE then -- fully flush, just end current stack | |
--print('+ ' .. toBits(stackNumber)) | |
table.insert(ints, stackNumber) | |
stackSize = CHUNK_SIZE -- set to CHUNK_SIZE because the usual code expects an already incremented stack size | |
stackNumber = 0 | |
-- continue as usual! | |
else -- crop one chunk into two | |
local shaveOffLeft = CHUNK_SIZE - shaveOff | |
local shaveOffRight = shaveOff | |
--print('shaving off l' .. shaveOffLeft .. ' r' .. shaveOffRight) | |
local left = bit32.band(createMask(shaveOffLeft), v) | |
local right = bit32.band(bit32.lshift(createMask(shaveOffRight), shaveOffLeft), v) | |
local offset = stackSize - CHUNK_SIZE | |
local newStackNumber = bit32.bor(stackNumber, bit32.lshift(left, offset)) | |
--print('s:' .. toBits(stackNumber) .. ' + ' .. toBits(left, shaveOffLeft) .. ' at ' .. offset .. ' = ' .. toBits(newStackNumber)) | |
stackNumber = newStackNumber | |
--print('+ ' .. toBits(stackNumber)) | |
table.insert(ints, stackNumber) | |
stackSize = CHUNK_SIZE - shaveOffLeft | |
stackNumber = 0 | |
v = right | |
-- continue as usual (with an asterisk) | |
end | |
end | |
local offset = stackSize - CHUNK_SIZE | |
local shiftedNum = v | |
if offset ~= 0 then shiftedNum = bit32.lshift(shiftedNum, offset) end | |
local newStackNumber = bit32.bor(stackNumber, shiftedNum) | |
--print(toBits(stackNumber) .. ' + ' .. toBits(v, CHUNK_SIZE) .. ' at ' .. offset .. ' = ' .. toBits(newStackNumber, stackSize)) | |
stackNumber = newStackNumber | |
end | |
-- push the remainder of the stack, if it exists | |
if stackSize > 0 then | |
--print('+ ' .. toBits(stackNumber)) | |
table.insert(ints, stackNumber) | |
end | |
return ints | |
end | |
--- given a table of encoded integers, decodes it into palette-sized color ints | |
--- | |
---@param d number[] | |
---@return number[] | |
function decodeData(d) | |
local ints = {} | |
local stackSize = 0 | |
local stackNumber = 0 | |
for _, n in ipairs(d) do | |
local curNum = n | |
for i = 1, INT_SIZE do | |
-- select the bit | |
local bit = bit32.band(1, curNum) -- 10000 & n | |
-- push the number to the left | |
--print(toBits(curNum, math.min(INT_SIZE - i + 2, INT_SIZE))) | |
curNum = bit32.rshift(curNum, 1) | |
--print(#ints .. ' queue: ' .. bit .. ' <- ' .. toBits(curNum, INT_SIZE - i + 1)) | |
-- push the bit onto our stack | |
stackNumber = bit32.bor(stackNumber, bit32.lshift(bit, stackSize)) | |
stackSize = stackSize + 1 | |
if stackSize >= CHUNK_SIZE then | |
-- we got a full stack! | |
table.insert(ints, stackNumber) | |
--print(' -> ' .. stackNumber) | |
stackSize = 0 | |
stackNumber = 0 | |
end | |
end | |
end | |
if stackSize > 0 then | |
-- incomplete stack, oh well | |
table.insert(ints, stackNumber) | |
end | |
return ints | |
end | |
-- syncing | |
local dataSent = {} | |
STRING_OFFSET = 12 -- offset charcodes by how much? | |
--[[ | |
PACKET FORMAT | |
each ping is a sequence of characters of size N (referred from now on as a packet). | |
each packet starts with a number, followed by a dot, after which the raw data is sent. the number indicates the index at which to write the data to | |
for example, given the packet "50.data", you would start writing at index 50 (1-indexed), decode "data", and write that there. | |
the reason its split this way is to allow for easier batching without stuff like desyncs interfering with the draw order | |
lost packets will also not be too destructive because the lost pixels will likely be resent later on | |
]] | |
ping.set = function(s) | |
local match = s:match('(.-)%.') | |
if not match then -- malformed packet. ignore, but leave a warning | |
print('malformed packet, ignoring') | |
return | |
end | |
local index = tonumber(match) | |
if not index then -- malformed number. ignore, but leave a warning | |
print('malformed number "' .. match .. '", ignoring') | |
return | |
end | |
local data = s:sub(#match + 2) | |
-- index is defined. lets start writing! | |
local ints = {} | |
for i = 1, string.len(data) do | |
table.insert(ints, string.byte(string.sub(data, i)) - STRING_OFFSET) | |
end | |
local decoded = decodeData(ints) | |
--print('recieved ' .. #data .. ' bytes, ' .. #decoded .. ' chunks') | |
-- write | |
writeState(1, decoded) | |
end | |
function writeState(index, state) | |
for i, d in pairs(state) do | |
local writeAt = index + i - 1 | |
local pix = c[tostring(writeAt)] | |
if not pix then break end -- we're oob; discard everything | |
local col = PALETTE[d + 1] | |
pix.setColor(col) | |
end | |
end | |
function syncState(state) | |
local s = {} | |
for _, v in ipairs(encodeData(state)) do | |
table.insert(s, string.char(v + STRING_OFFSET)) | |
end | |
--print('sending ' .. #s .. ' bytes, ' .. #state .. ' chunks') | |
-- currently just write at i1 | |
local str = '1.' .. table.concat(s, '') | |
table.insert(dataSent, {ticks, #str}) | |
ping.set(str) | |
end | |
-- kb/s | |
if client.isHost() then | |
function tick() | |
local sum = 0 | |
for i = #dataSent, 1, -1 do | |
if ticks - dataSent[i][1] > 20 then | |
table.remove(dataSent, i) | |
else | |
sum = sum + dataSent[i][2] | |
end | |
end | |
nameplate.ENTITY.setText(sum .. 'b/s') | |
end | |
end | |
if client.isHost() then | |
local font = { | |
[' '] = { | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
}, | |
['!'] = { | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 1, 0, 0, | |
}, | |
['"'] = { | |
0, 1, 0, 1, 0, | |
0, 1, 0, 1, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
}, | |
['#'] = { | |
0, 1, 0, 1, 0, | |
1, 1, 1, 1, 1, | |
0, 1, 0, 1, 0, | |
1, 1, 1, 1, 1, | |
0, 1, 0, 1, 0, | |
}, | |
['$'] = { | |
0, 1, 1, 1, 1, | |
1, 0, 1, 0, 0, | |
0, 1, 1, 1, 0, | |
0, 0, 1, 0, 1, | |
1, 1, 1, 1, 0, | |
}, | |
['%'] = { | |
1, 1, 0, 0, 1, | |
1, 1, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 0, 1, 1, | |
1, 0, 0, 1, 1, | |
}, | |
['&'] = { | |
0, 0, 1, 0, 0, | |
0, 1, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 0, 1, 0, | |
0, 0, 1, 0, 1, | |
}, | |
['\''] = { | |
0, 0, 1, 0, 0, | |
0, 1, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
}, | |
['('] = { | |
0, 0, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 0, 1, 0, | |
}, | |
[')'] = { | |
0, 1, 0, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 0, 0, 0, | |
}, | |
['*'] = { | |
1, 0, 1, 0, 1, | |
0, 1, 1, 1, 0, | |
1, 1, 1, 1, 1, | |
0, 1, 1, 1, 0, | |
1, 0, 1, 0, 1, | |
}, | |
['+'] = { | |
0, 0, 0, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 1, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 0, 0, 0, | |
}, | |
[','] = { | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 0, 0, 0, | |
}, | |
['-'] = { | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 1, 1, 1, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
}, | |
['.'] = { | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 1, 0, 0, | |
}, | |
['/'] = { | |
0, 0, 0, 0, 1, | |
0, 0, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 0, 0, 0, | |
1, 0, 0, 0, 0, | |
}, | |
['0'] = { | |
0, 1, 1, 1, 0, | |
1, 0, 0, 1, 1, | |
1, 0, 1, 0, 1, | |
1, 1, 0, 0, 1, | |
0, 1, 1, 1, 0, | |
}, | |
['1'] = { | |
0, 0, 1, 0, 0, | |
0, 1, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 1, 1, 0, | |
}, | |
['2'] = { | |
0, 1, 1, 0, 0, | |
1, 0, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 0, 0, 0, | |
1, 1, 1, 1, 0, | |
}, | |
['3'] = { | |
0, 1, 1, 0, 0, | |
0, 0, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 0, 1, 0, | |
0, 1, 1, 0, 0, | |
}, | |
['4'] = { | |
0, 0, 1, 1, 0, | |
0, 1, 0, 1, 0, | |
0, 1, 1, 1, 1, | |
0, 0, 0, 1, 0, | |
0, 0, 0, 1, 0, | |
}, | |
['5'] = { | |
0, 1, 1, 1, 0, | |
0, 1, 0, 0, 0, | |
0, 1, 1, 0, 0, | |
0, 0, 0, 1, 0, | |
0, 1, 1, 0, 0, | |
}, | |
['6'] = { | |
0, 0, 1, 0, 0, | |
0, 1, 0, 0, 0, | |
1, 1, 1, 0, 0, | |
1, 0, 0, 1, 0, | |
0, 1, 1, 0, 0, | |
}, | |
['7'] = { | |
0, 1, 1, 1, 1, | |
0, 0, 0, 0, 1, | |
0, 0, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
}, | |
['8'] = { | |
0, 1, 1, 0, 0, | |
1, 0, 0, 1, 0, | |
0, 1, 1, 0, 0, | |
1, 0, 0, 1, 0, | |
0, 1, 1, 0, 0, | |
}, | |
['9'] = { | |
0, 1, 1, 0, 0, | |
1, 0, 0, 1, 0, | |
0, 1, 1, 1, 0, | |
0, 0, 0, 1, 0, | |
0, 0, 0, 1, 0, | |
}, | |
[':'] = { | |
0, 0, 0, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 0, 0, 0, | |
}, | |
[';'] = { | |
0, 0, 0, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 0, 0, 0, | |
}, | |
['<'] = { | |
0, 0, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 0, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 0, 1, 0, | |
}, | |
['='] = { | |
0, 0, 0, 0, 0, | |
0, 1, 1, 1, 0, | |
0, 0, 0, 0, 0, | |
0, 1, 1, 1, 0, | |
0, 0, 0, 0, 0, | |
}, | |
['>'] = { | |
0, 1, 0, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 0, 0, 0, | |
}, | |
['?'] = { | |
0, 1, 1, 0, 0, | |
0, 0, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 1, 0, 0, | |
}, | |
['@'] = { | |
0, 1, 1, 1, 0, | |
0, 0, 0, 0, 1, | |
0, 1, 1, 0, 1, | |
1, 0, 1, 0, 1, | |
0, 1, 1, 1, 0, | |
}, | |
['A'] = { | |
0, 1, 1, 1, 0, | |
1, 0, 0, 0, 1, | |
1, 1, 1, 1, 1, | |
1, 0, 0, 0, 1, | |
1, 0, 0, 0, 1, | |
}, | |
['B'] = { | |
1, 1, 1, 1, 0, | |
1, 0, 0, 0, 1, | |
1, 1, 1, 1, 0, | |
1, 0, 0, 0, 1, | |
1, 1, 1, 1, 0, | |
}, | |
['C'] = { | |
0, 1, 1, 1, 1, | |
1, 0, 0, 0, 0, | |
1, 0, 0, 0, 0, | |
1, 0, 0, 0, 0, | |
0, 1, 1, 1, 1, | |
}, | |
['D'] = { | |
1, 1, 1, 1, 0, | |
1, 0, 0, 0, 1, | |
1, 0, 0, 0, 1, | |
1, 0, 0, 0, 1, | |
1, 1, 1, 1, 0, | |
}, | |
['E'] = { | |
1, 1, 1, 1, 1, | |
1, 0, 0, 0, 0, | |
1, 1, 1, 1, 0, | |
1, 0, 0, 0, 0, | |
1, 1, 1, 1, 1, | |
}, | |
['F'] = { | |
1, 1, 1, 1, 1, | |
1, 0, 0, 0, 0, | |
1, 1, 1, 1, 0, | |
1, 0, 0, 0, 0, | |
1, 0, 0, 0, 0, | |
}, | |
['G'] = { | |
0, 1, 1, 1, 1, | |
1, 0, 0, 0, 0, | |
1, 0, 0, 1, 1, | |
1, 0, 0, 0, 1, | |
0, 1, 1, 1, 1, | |
}, | |
['H'] = { | |
1, 0, 0, 0, 1, | |
1, 0, 0, 0, 1, | |
1, 1, 1, 1, 1, | |
1, 0, 0, 0, 1, | |
1, 0, 0, 0, 1, | |
}, | |
['I'] = { | |
0, 1, 1, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 1, 1, 0, | |
}, | |
['J'] = { | |
0, 0, 1, 1, 1, | |
0, 0, 0, 1, 0, | |
0, 0, 0, 1, 0, | |
1, 0, 0, 1, 0, | |
0, 1, 1, 0, 0, | |
}, | |
['K'] = { | |
1, 0, 0, 1, 0, | |
1, 0, 1, 0, 0, | |
1, 1, 0, 0, 0, | |
1, 0, 1, 0, 0, | |
1, 0, 0, 1, 0, | |
}, | |
['L'] = { | |
1, 0, 0, 0, 0, | |
1, 0, 0, 0, 0, | |
1, 0, 0, 0, 0, | |
1, 0, 0, 0, 0, | |
1, 1, 1, 1, 0, | |
}, | |
['M'] = { | |
1, 0, 0, 0, 1, | |
1, 1, 0, 1, 1, | |
1, 0, 1, 0, 1, | |
1, 0, 0, 0, 1, | |
1, 0, 0, 0, 1, | |
}, | |
['N'] = { | |
1, 0, 0, 0, 1, | |
1, 1, 0, 0, 1, | |
1, 0, 1, 0, 1, | |
1, 0, 0, 1, 1, | |
1, 0, 0, 0, 1, | |
}, | |
['O'] = { | |
0, 1, 1, 1, 0, | |
1, 0, 0, 0, 1, | |
1, 0, 0, 0, 1, | |
1, 0, 0, 0, 1, | |
0, 1, 1, 1, 0, | |
}, | |
['P'] = { | |
1, 1, 1, 1, 0, | |
1, 0, 0, 0, 1, | |
1, 1, 1, 1, 0, | |
1, 0, 0, 0, 0, | |
1, 0, 0, 0, 0, | |
}, | |
['Q'] = { | |
0, 1, 1, 1, 0, | |
1, 0, 0, 0, 1, | |
1, 0, 0, 0, 1, | |
1, 0, 0, 1, 0, | |
0, 1, 1, 0, 1, | |
}, | |
['R'] = { | |
1, 1, 1, 1, 0, | |
1, 0, 0, 0, 1, | |
1, 1, 1, 1, 0, | |
1, 0, 1, 0, 0, | |
1, 0, 0, 1, 0, | |
}, | |
['S'] = { | |
0, 1, 1, 1, 1, | |
1, 0, 0, 0, 0, | |
0, 1, 1, 1, 0, | |
0, 0, 0, 0, 1, | |
1, 1, 1, 1, 0, | |
}, | |
['T'] = { | |
1, 1, 1, 1, 1, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
}, | |
['U'] = { | |
1, 0, 0, 0, 1, | |
1, 0, 0, 0, 1, | |
1, 0, 0, 0, 1, | |
1, 0, 0, 0, 1, | |
0, 1, 1, 1, 0, | |
}, | |
['V'] = { | |
1, 0, 0, 0, 1, | |
1, 0, 0, 0, 1, | |
1, 0, 0, 0, 1, | |
0, 1, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
}, | |
['W'] = { | |
1, 0, 0, 0, 1, | |
1, 0, 0, 0, 1, | |
1, 0, 1, 0, 1, | |
1, 0, 1, 0, 1, | |
0, 1, 0, 1, 0, | |
}, | |
['X'] = { | |
1, 0, 0, 0, 1, | |
0, 1, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 0, 1, 0, | |
}, | |
['Z'] = { | |
1, 1, 1, 1, 1, | |
0, 0, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 0, 0, 0, | |
1, 1, 1, 1, 1, | |
}, | |
['['] = { | |
0, 1, 1, 1, 0, | |
0, 1, 0, 0, 0, | |
0, 1, 0, 0, 0, | |
0, 1, 0, 0, 0, | |
0, 1, 1, 1, 0, | |
}, | |
['\\'] = { | |
1, 0, 0, 0, 0, | |
0, 1, 0, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 0, 1, 0, | |
0, 0, 0, 0, 1, | |
}, | |
[']'] = { | |
0, 1, 1, 1, 0, | |
0, 0, 0, 1, 0, | |
0, 0, 0, 1, 0, | |
0, 0, 0, 1, 0, | |
0, 1, 1, 1, 0, | |
}, | |
['^'] = { | |
0, 0, 1, 0, 0, | |
0, 1, 0, 1, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
}, | |
['_'] = { | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
1, 1, 1, 1, 1, | |
}, | |
['`'] = { | |
0, 1, 0, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
}, | |
['a'] = { | |
0, 0, 0, 0, 0, | |
0, 1, 1, 1, 0, | |
1, 0, 0, 1, 0, | |
1, 0, 0, 1, 0, | |
0, 1, 1, 0, 1, | |
}, | |
['b'] = { | |
1, 0, 0, 0, 0, | |
1, 1, 1, 0, 0, | |
1, 0, 0, 1, 0, | |
1, 0, 0, 1, 0, | |
1, 1, 1, 0, 0, | |
}, | |
['c'] = { | |
0, 0, 0, 0, 0, | |
0, 0, 1, 1, 0, | |
0, 1, 0, 0, 0, | |
0, 1, 0, 0, 0, | |
0, 0, 1, 1, 0, | |
}, | |
['d'] = { | |
0, 0, 0, 1, 0, | |
0, 0, 0, 1, 0, | |
0, 1, 1, 1, 0, | |
1, 0, 0, 1, 0, | |
0, 1, 1, 1, 0, | |
}, | |
['e'] = { | |
0, 0, 0, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 0, 1, 0, | |
0, 1, 1, 0, 0, | |
0, 0, 1, 1, 0, | |
}, | |
['f'] = { | |
0, 0, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 1, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
}, | |
['g'] = { | |
0, 0, 1, 1, 0, | |
0, 1, 0, 1, 0, | |
0, 0, 1, 1, 0, | |
0, 0, 0, 1, 0, | |
0, 1, 1, 0, 0, | |
}, | |
['h'] = { | |
0, 1, 0, 0, 0, | |
0, 1, 0, 0, 0, | |
0, 1, 1, 1, 0, | |
0, 1, 0, 0, 1, | |
0, 1, 0, 0, 1, | |
}, | |
['i'] = { | |
0, 0, 1, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
}, | |
['j'] = { | |
0, 0, 0, 1, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 0, 1, 0, | |
0, 1, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
}, | |
['k'] = { | |
0, 1, 0, 0, 0, | |
0, 1, 0, 0, 0, | |
0, 1, 0, 1, 0, | |
0, 1, 1, 0, 0, | |
0, 1, 0, 1, 0 | |
}, | |
['l'] = { | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
}, | |
['m'] = { | |
0, 0, 0, 0, 0, | |
1, 1, 0, 1, 0, | |
1, 0, 1, 0, 1, | |
1, 0, 0, 0, 1, | |
1, 0, 0, 0, 1, | |
}, | |
['n'] = { | |
0, 0, 0, 0, 0, | |
0, 1, 1, 0, 0, | |
0, 1, 0, 1, 0, | |
0, 1, 0, 1, 0, | |
0, 1, 0, 1, 0, | |
}, | |
['o'] = { | |
0, 0, 0, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 0, 1, 0, | |
0, 1, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
}, | |
['p'] = { | |
0, 0, 0, 0, 0, | |
0, 1, 1, 0, 0, | |
0, 1, 0, 1, 0, | |
0, 1, 1, 0, 0, | |
0, 1, 0, 0, 0, | |
}, | |
['q'] = { | |
0, 0, 0, 0, 0, | |
0, 0, 1, 1, 0, | |
0, 1, 0, 1, 0, | |
0, 0, 1, 1, 0, | |
0, 0, 0, 1, 0, | |
}, | |
['r'] = { | |
0, 0, 0, 0, 0, | |
0, 1, 0, 1, 0, | |
0, 1, 1, 0, 0, | |
0, 1, 0, 0, 0, | |
0, 1, 0, 0, 0, | |
}, | |
['s'] = { | |
0, 0, 0, 0, 0, | |
0, 0, 1, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 0, 1, 0, | |
0, 0, 1, 1, 0, | |
}, | |
['t'] = { | |
0, 0, 1, 0, 0, | |
0, 1, 1, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 0, 1, 0, | |
}, | |
['u'] = { | |
0, 0, 0, 0, 0, | |
0, 1, 0, 0, 1, | |
0, 1, 0, 0, 1, | |
0, 1, 0, 0, 1, | |
0, 0, 1, 1, 0, | |
}, | |
['v'] = { | |
0, 0, 0, 0, 0, | |
0, 1, 0, 1, 0, | |
0, 1, 0, 1, 0, | |
0, 1, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
}, | |
['w'] = { | |
0, 0, 0, 0, 0, | |
1, 0, 0, 0, 1, | |
1, 0, 1, 0, 1, | |
1, 0, 1, 0, 1, | |
0, 1, 0, 1, 0, | |
}, | |
['x'] = { | |
0, 0, 0, 0, 0, | |
0, 1, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 0, 1, 0, | |
}, | |
['y'] = { | |
0, 0, 0, 0, 0, | |
0, 1, 0, 1, 0, | |
0, 1, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 0, 0, 0, | |
}, | |
['z'] = { | |
0, 0, 0, 0, 0, | |
0, 0, 1, 1, 0, | |
0, 0, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 1, 0, | |
}, | |
['{'] = { | |
0, 0, 0, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 0, 1, 0, | |
}, | |
['|'] = { | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 0, 0, | |
}, | |
['}'] = { | |
0, 1, 0, 0, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 1, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 1, 0, 0, 0, | |
}, | |
['~'] = { | |
0, 0, 0, 0, 0, | |
0, 0, 1, 0, 1, | |
0, 1, 0, 1, 0, | |
0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, | |
} | |
} | |
local fontValues = {} -- {start, end} | |
local fontWidth = 5 | |
local fontHeight = 5 | |
for k, v in pairs(font) do | |
local start | |
local en | |
for x = 1, fontWidth do | |
local emptyLine = true | |
for y = 1, fontHeight do | |
if v[x + (y - 1) * fontWidth] ~= 0 then | |
emptyLine = false | |
break | |
end | |
end | |
if not emptyLine then | |
if not start then | |
start = x | |
else | |
en = x | |
end | |
end | |
end | |
start = start or 2 | |
fontValues[k] = {start, en or start} | |
end | |
fontValues[' '] = {2, 4} | |
local line = '1234' | |
function tick() | |
local state = {} | |
for i = 1, sw * sh do | |
state[i] = 0 | |
end | |
local x = 0 | |
local y = 0 | |
for i = 1, #line do | |
local c = line:sub(i, i) | |
local f = font[c] or font['?'] | |
local fv = fontValues[c] or fontValues['?'] | |
local newx = x + fv[2] - fv[1] + 2 | |
if newx > sw then | |
x = 0 | |
y = y + fontHeight + 1 | |
newx = x + fv[2] - fv[1] + 2 | |
end | |
for x2 = 1, fontWidth do | |
for y2 = 1, fontHeight do | |
local idx = xyToIndex(x + x2 - fv[1] + 1, y + y2) | |
local v = f[x2 + (y2 - 1) * fontWidth] | |
if v == 1 then state[idx] = math.random(1, 3) end | |
end | |
end | |
x = newx | |
end | |
--writeState(1, state) | |
if ticks % 5 == 0 then | |
syncState(state) | |
end | |
end | |
chat.setFiguraCommandPrefix('>') | |
function onCommand(str) | |
line = string.sub(str, 2) | |
end | |
-- sync shit up | |
function tick() | |
if monitorpos and ticks % 20 == 0 then | |
ping.setpos(monitorpos) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment