info = { type = "image", title = "Advent grid", category = "holidays", author = "BRRRO", version = "1.0", license = "MIT", desc = "Advent calendar windows open one by one", api = 33, } local tr = ({ sk = { ["Speed"] = "Rýchlosť", ["Numbers"] = "Čísla", slow = "pomaly", normal = "normálne", fast = "rýchlo" }, cs = { ["Speed"] = "Rychlost", ["Numbers"] = "Čísla", slow = "pomalu", normal = "normálně", fast = "rychle" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "speed", label = T("Speed"), type = "int", default = 1, opts = { T("slow"), T("normal"), T("fast") } }, { key = "nums", label = T("Numbers"), type = "bool", default = true }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local hash32, umod = math.hash32, math.umod local W, FPS = gfx.W, gfx.FPS local CELL, PITCH, X0, Y0 = 13, 15, 3, 3 local WALL, FRAME, SNOW = { 188, 150, 112 }, { 236, 236, 242 }, { 242, 246, 252 } local RED, GREEN, CREAM = { 176, 36, 44 }, { 30, 112, 66 }, { 250, 238, 204 } local DAY, DAY_FLOOR = { 150, 200, 232 }, { 242, 246, 252 } local NIGHT, NIGHT_FLOOR = { 26, 36, 92 }, { 150, 172, 214 } local DARK, ORANGE, GOLD = { 40, 34, 52 }, { 246, 140, 30 }, { 250, 200, 60 } local function c3(c) return c[1], c[2], c[3] end local X, Y local function r(i, j, w, h, c) rect(X + i, Y + j, w, h, c3(c)) end local function p(i, j, c) px(X + i, Y + j, c3(c)) end local function snowman(scarf) return function() r(3, 5, 5, 4, SNOW); r(2, 6, 7, 2, SNOW) r(3, 2, 5, 3, SNOW); r(4, 1, 3, 1, SNOW) r(3, 1, 5, 1, DARK); r(4, 0, 3, 1, DARK) p(4, 3, DARK); p(6, 3, DARK); p(5, 4, ORANGE) r(3, 5, 5, 1, scarf); p(2, 6, { 120, 70, 40 }); p(8, 6, { 120, 70, 40 }) p(5, 7, DARK); p(5, 8, DARK) r(3, 8, 5, 1, { 200, 214, 232 }) end end local function gift(c, ribbon) return function() r(3, 5, 5, 4, c); r(5, 5, 1, 4, ribbon); r(3, 6, 5, 1, ribbon) p(4, 4, ribbon); p(6, 4, ribbon); p(5, 3, ribbon) end end local BROWN = { 130, 84, 52 } local SCENES = { { snowman(RED), "day" }, { gift(RED, GOLD), "day" }, { function() r(3, 5, 4, 4, { 80, 80, 104 }); r(3, 3, 4, 2, { 80, 80, 104 }) p(3, 2, { 80, 80, 104 }); p(6, 2, { 80, 80, 104 }) p(4, 4, GOLD); p(5, 4, GOLD); r(7, 6, 1, 3, { 80, 80, 104 }); p(8, 5, { 80, 80, 104 }) end, "day" }, { snowman({ 30, 160, 80 }), "day" }, { function() r(3, 7, 5, 1, { 190, 40, 40 }) r(4, 5, 3, 3, CREAM) local f = (frame // 4) % 3 p(5, 3, GOLD); p(5, 4, ORANGE) if f == 1 then p(4, 3, { 120, 70, 30 }) elseif f == 2 then p(6, 3, { 120, 70, 30 }) end blend_rect(X + 2, Y + 1, 7, 7, 255, 170, 60, 0.12) end, "night" }, { function() local G = { 40, 140, 76 } r(5, 1, 1, 1, G); r(4, 2, 3, 1, G); r(3, 3, 5, 1, G); r(4, 4, 3, 1, G) r(2, 5, 7, 1, G); r(1, 6, 9, 1, G); r(5, 7, 1, 2, BROWN) p(5, 0, GOLD); p(4, 3, RED); p(6, 5, GOLD); p(3, 6, GOLD); p(7, 6, RED) end, "day" }, { function() r(3, 3, 5, 5, DARK); r(4, 2, 3, 1, DARK); r(4, 4, 3, 4, { 240, 240, 250 }) p(4, 3, { 240, 240, 250 }); p(6, 3, { 240, 240, 250 }) p(5, 4, ORANGE); p(4, 8, ORANGE); p(6, 8, ORANGE) end, "day" }, { snowman({ 240, 210, 40 }), "day" }, { function() r(5, 1, 1, 2, GOLD); r(2, 3, 7, 1, GOLD); r(3, 4, 5, 2, GOLD) r(2, 6, 2, 1, GOLD); r(7, 6, 2, 1, GOLD) if (frame // 12) % 2 == 0 then p(1, 1, CREAM); p(9, 2, CREAM) else p(9, 1, CREAM); p(1, 2, CREAM) end end, "night" }, { gift(GREEN, CREAM), "day" }, { function() r(3, 5, 5, 3, BROWN); r(3, 8, 1, 1, BROWN); r(7, 8, 1, 1, BROWN) r(7, 3, 1, 3, BROWN); r(8, 3, 2, 2, BROWN); p(9, 4, RED) p(8, 2, BROWN); p(9, 1, BROWN); p(7, 1, BROWN); p(2, 5, SNOW) end, "day" }, { function() local B = { 190, 120, 60 } r(4, 1, 3, 2, B); r(4, 3, 3, 3, B); r(2, 3, 7, 1, B) r(3, 6, 2, 2, B); r(6, 6, 2, 2, B) p(4, 2, DARK); p(6, 2, DARK); p(5, 4, SNOW); p(5, 5, SNOW) end, "day" }, { function() r(4, 2, 3, 1, GOLD); r(3, 3, 5, 3, GOLD); r(2, 6, 7, 1, GOLD) p(5, 7, DARK); r(5, 1, 1, 1, RED); p(4, 4, { 255, 236, 150 }) end, "day" }, { snowman({ 90, 120, 230 }), "day" }, { function() local M = { 244, 236, 190 } r(4, 1, 3, 1, M); r(3, 2, 2, 1, M); r(2, 3, 2, 3, M); r(3, 6, 2, 1, M); r(4, 7, 3, 1, M) p(8, 3, CREAM); p(7, 5, CREAM); p(9, 1, CREAM) end, "night" }, { function() r(4, 1, 3, 1, SNOW); r(4, 2, 3, 4, RED); r(4, 6, 5, 2, RED); p(8, 6, RED) p(5, 3, GOLD); p(6, 4, GREEN) end, "night" }, } local LEAF = { { 6, 5 }, { 4, 4 }, { 3, 3 }, { 2, 2 }, { 1, 1 } } local function flakes(k) for i = 0, 2 do local h = hash32(k * 0x9E3779B1 + i * 0x85EBCA6B) local fx = (umod(h, 11) + (frame // 24) % 2 * (i - 1)) % 11 local fy = (frame // 5 + umod(h >> 8, 9)) % 9 p(fx, fy, { 255, 255, 255 }) end end local function leaves(k, pose, nums) local c = ((k // 4) + (k % 4)) % 2 == 0 and RED or GREEN local lw, rw = LEAF[pose + 1][1], LEAF[pose + 1][2] local dk = { c[1] * 0.7, c[2] * 0.7, c[3] * 0.7 } r(0, 0, lw, 11, c); r(11 - rw, 0, rw, 11, c) r(lw - 1, 0, 1, 11, dk); r(11 - rw, 0, 1, 11, dk) if pose == 0 and nums then gfx.text(X, Y + 3, tostring(k + 1), CREAM[1], CREAM[2], CREAM[3], { font = "3x5", w = 11, align = "center" }) end end local function cell(k, pose, nums) local cx, cy = X0 + (k % 4) * PITCH, Y0 + (k // 4) * PITCH rect(cx, cy, CELL, CELL, c3(FRAME)) X, Y = cx + 1, cy + 1 local sc = SCENES[k + 1] local night = sc[2] == "night" r(0, 0, 11, 9, night and NIGHT or DAY) r(0, 9, 11, 2, night and NIGHT_FLOOR or DAY_FLOOR) if pose > 0 then sc[1]() if not night then flakes(k) end end leaves(k, pose, nums) rect(cx - 1, cy + CELL, CELL + 2, 1, c3(SNOW)) end local BG, NUMS = nil, true local SLOT = 54 function on_settings() NUMS = cfg.nums ~= false SLOT = ({ 80, 54, 36 })[(cfg.speed or 1) + 1] BG = nil end local function build_bg() rect(0, 0, W, W, c3(WALL)) for k = 0, 15 do cell(k, 0, NUMS) end BG = gfx.snapshot(0, 0, W, W) end local perms = {} local function perm(n) local t = perms[n] if not t then t = {} for i = 1, 16 do t[i] = i - 1 end for i = 16, 2, -1 do local j = 1 + umod(hash32(n * 0x9E3779B1 + i * 0x85EBCA6B), i) t[i], t[j] = t[j], t[i] end perms = { [n] = t, [n - 1] = perms[n - 1] } end return t end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, W) local j = frame // SLOT local life = 2 * SLOT for jj = j - 1, j do if jj >= 0 then local u = frame - jj * SLOT local pose = 4 if u < 12 then pose = u // 3 elseif u >= life - 12 then pose = 3 - (u - (life - 12)) // 3 end cell(perm(jj // 16)[jj % 16 + 1], pose, NUMS) end end end