counter.lua
local blocks = require "shado.lib.blocks"
local frames = require "shado.lib.frames"
local patterns = {
"111 101 101 101 111", "110 010 010 010 111", "111 001 111 100 111", "111 001 111 001 111", "101 101 111 001 001", "111 100 111 001 111", "111 100 111 101 111", "111 001 001 001 001", "111 101 111 101 111", "111 101 111 001 111" }
local tensFrame = frames.Frame:new()
local unitsFrame = frames.Frame:new()
local outerFrame = frames.Frame:new():add(tensFrame, 5, 2):add(unitsFrame, 10, 2)
local blockObjects = { }
for _, v in ipairs(patterns) do
local b = blocks.Block:new(v)
table.insert(blockObjects, b)
tensFrame:add(b, 1, 1)
unitsFrame:add(b, 1, 1)
end
return {
layer = outerFrame,
count = function (self, i)
local tens = ((i // 10) % 10) + 1
local units = (i % 10) + 1
tensFrame:top(blockObjects[tens])
unitsFrame:top(blockObjects[units])
end,
displayText = [[
Counter
Digit glyphs, counting to 99.
No button interaction.
]]
}