pyramids.lua
local types = require "shado.lib.types"
local blocks = require "shado.lib.blocks"
local frames = require "shado.lib.frames"
function randomLamp()
local level = math.random() local blend = math.random() * 2 - 1
return types.LampState:new(level, blend)
end
function makeLayer(size)
local b = blocks.Block:new(size, size):fill(randomLamp())
b.press =
function(self, x, y, how)
if how > 0 then
b:fill(randomLamp())
end
end
local offset = (8 - size) // 2
local f = frames.Frame:new():add(b, 1 + offset, 1 + offset)
return f
end
local frame = frames.Frame:new()
for i = 8, 2, -2 do
frame:add(makeLayer(i), 1, 1)
end
for i = 8, 2, -2 do
frame:add(makeLayer(i), 9, 1)
end
return {
layer = frame,
displayText = [[
Pyramids
Two stacks of concentric
squares, 2x2 to 8x8.
Press to randomise level and
opacity of selected square.
]]
}