info = { type = "image", title = "Pug in a stocking", category = "holidays", author = "BRRRO", version = "1.0", license = "MIT", desc = "Pug in a Santa hat swaying in a red stocking", api = 44, } local tr = ({ sk = { ["Sway"] = "Kývanie", ["Snow"] = "Sneh", ["Tongue"] = "Jazyk", ["Fairy lights"] = "Svetielka" }, cs = { ["Sway"] = "Houpání", ["Snow"] = "Sníh", ["Tongue"] = "Jazyk", ["Fairy lights"] = "Světýlka" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "sway", label = T("Sway"), type = "int", min = 1, max = 5, default = 3 }, { key = "snow", label = T("Snow"), type = "int", min = 0, max = 5, default = 3 }, { key = "tongue", label = T("Tongue"), type = "bool", default = true }, { key = "lights", label = T("Fairy lights"), type = "bool", default = true }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local blit_rgb, snapshot = gfx.blit_rgb, gfx.snapshot local floor, sin, sqrt, min, max, exp = math.floor, math.sin, math.sqrt, math.min, math.max, math.exp local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local C, PIVY = 30, 5 local KR, KG, KB = 255, 0, 255 local FUR, FURL, FURD = { 222, 178, 118 }, { 244, 212, 156 }, { 176, 126, 80 } local EAR, EARL, MASK, MASKL = { 84, 54, 42 }, { 120, 84, 62 }, { 44, 34, 36 }, { 98, 78, 72 } local RED, REDL, REDD = { 206, 28, 40 }, { 240, 74, 70 }, { 138, 16, 34 } local WHITE, WHD, EYE = { 250, 250, 255 }, { 204, 212, 232 }, { 28, 20, 24 } local TONGUE, TONGUED, GOLD = { 240, 104, 128 }, { 188, 62, 92 }, { 216, 174, 64 } local function c3(c) return c[1], c[2], c[3] end local function R(c, x, y, w, h) if w > 0 then rect(x, y, w, h, c[1], c[2], c[3]) end end local function P1(c, x, y) px(x, y, c[1], c[2], c[3]) end local function lerp(a, b, t) return a + (b - a) * t end local EAR_REST = { { 16, 11, 3 }, { 17, 12, 4 }, { 18, 12, 4 }, { 19, 12, 4 }, { 20, 12, 4 }, { 21, 11, 4 }, { 22, 11, 3 }, { 23, 10, 3 }, { 24, 10, 2 } } local EAR_UP = { { 13, 11, 2 }, { 14, 11, 3 }, { 15, 12, 4 }, { 16, 12, 4 }, { 17, 12, 4 }, { 18, 12, 4 }, { 19, 12, 4 }, { 20, 12, 4 }, { 21, 11, 4 }, { 22, 11, 3 }, { 23, 10, 3 }, { 24, 10, 2 } } local function ear(rows, side) for i = 1, #rows do local r = rows[i] local x = side < 0 and C - r[2] or C + r[2] - r[3] + 1 R(EAR, x, r[1], r[3], 1) if r[1] >= 18 and r[1] <= 21 then P1(EARL, side < 0 and x + 1 or x + r[3] - 2, r[1]) end end end local function paint(v) R({ KR, KG, KB }, 0, PIVY, W, 58) local XR = { [52] = 11, [53] = 15, [54] = 19, [55] = 21, [56] = 22, [57] = 22, [58] = 22, [59] = 21, [60] = 18, [61] = 13 } local XL = { [50] = 11, [51] = 12, [52] = 12, [53] = 12, [54] = 12, [55] = 12, [56] = 12, [57] = 12, [58] = 12, [59] = 11, [60] = 10, [61] = 8 } for y = 40, 61 do local xl, xr = C - (XL[y] or 10), C + (XR[y] or 10) local w = xr - xl + 1 R(RED, xl, y, w, 1) R(REDL, xl, y, 3, 1) R(REDD, xr - 2, y, 3, 1) if y == 61 then R(REDD, xl, y, w, 1) end end for x = C - 8, C + 8, 4 do P1(WHITE, x, 44); P1(WHITE, x + 2, 46); P1(GOLD, x + 1, 45) end R(WHITE, C - 12, 52, 4, 6); R(WHITE, C + 19, 54, 4, 6); R(WHD, C - 12, 57, 4, 1); R(WHD, C + 19, 59, 4, 1) R(FUR, C - 8, 30, 17, 6) for y = 34, 39 do local hw = (y == 34 or y == 39) and 10 or 11 R(y == 34 and WHITE or y == 39 and WHD or WHITE, C - hw, y, 2 * hw + 1, 1) end R(WHD, C - 11, 38, 23, 1) for x = C - 10, C + 10, 2 do P1(WHD, x, 40) end for x = C - 9, C + 9, 4 do P1(WHD, x, 36) end R(FUR, C - 10, 33, 4, 3); R(FURD, C - 10, 35, 4, 1); P1(FURD, C - 8, 34); P1(FURD, C - 7, 34) R(FUR, C + 7, 33, 4, 3); R(FURD, C + 7, 35, 4, 1); P1(FURD, C + 8, 34); P1(FURD, C + 9, 34) for y = 16, 32 do local hw = floor(11 * sqrt(1 - ((y - 24) / 8.6) ^ 2) + 0.5) R(FUR, C - hw, y, 2 * hw + 1, 1) if y < 27 then R(FURL, C - hw + 1, y, min(3, hw), 1) end R(FURD, C + hw - 1, y, 2, 1) if y >= 30 then R(FURD, C - hw + 2, y, 2 * hw - 3, 1) end end ear(v.earL and EAR_UP or EAR_REST, -1) ear(v.earR and EAR_UP or EAR_REST, 1) R(FURD, C - 2, 18, 5, 1); R(FURD, C - 5, 19, 3, 1); R(FURD, C + 3, 19, 3, 1) for y = 24, 32 do local hw = floor(6 * sqrt(1 - ((y - 28.2) / 4.6) ^ 2) + 0.5) R(MASK, C - hw, y, 2 * hw + 1, 1) end R(MASKL, C - 3, 25, 6, 1) R(EYE, C - 1, 26, 3, 2); P1(MASKL, C - 1, 26) for _, ex in ipairs({ C - 7, C + 4 }) do if v.blink then R(EYE, ex, 22, 4, 1) else R(EYE, ex, 20, 4, 4); P1(WHITE, ex + 1, 21); P1(WHITE, ex + 2, 22) end end if v.tongue then R(TONGUE, C - 1, 31, 3, 4); R(TONGUED, C, 31, 1, 4); P1(WHITE, C - 1, 32) end local WID = { 3, 5, 7, 9, 11, 13, 15 } for i = 1, 7 do local y = 6 + i local cx = C + floor((7 - i) * 0.7 + 1.5) local w = WID[i] R(RED, cx - w // 2, y, w, 1) R(REDL, cx - w // 2, y, min(2, w), 1) R(REDD, cx + w // 2 - 1, y, 2, 1) end for y = 14, 16 do local hw = y == 15 and 9 or 8 R(WHITE, C - hw, y, 2 * hw + 1, 1) end R(WHD, C - 8, 16, 17, 1) for x = C - 7, C + 7, 3 do P1(WHD, x, 15) end end local BG local function backdrop() for y = 0, H - 1 do local t = y / (H - 1) rect(0, y, W, 1, floor(lerp(14, 30, t) + 0.5), floor(lerp(28, 58, t) + 0.5), floor(lerp(66, 112, t) + 0.5)) end for y = 8, H - 1, 8 do for x = (y // 8) % 2 * 4, W - 1, 8 do px(x, y, 34, 66, 124) end end rect(0, 0, W, 4, 112, 70, 40) rect(0, 0, W, 1, 150, 100, 60) for x = 0, W - 1, 3 do px(x, 1 + (x // 3) % 2, 90, 54, 32) end rect(0, 3, W, 1, 70, 40, 24) blend_rect(0, 4, W, 1, 8, 10, 30, 0.45) R(GOLD, C, 4, 1, 2); R(GOLD, C + 1, 6, 1, 1); R({ 150, 116, 40 }, C, 5, 1, 1) BG = snapshot(0, 0, W, H) end local BASE, PB, PEL, PER, PT = {}, {}, {}, {}, {} local function rows(into, ya, yb) for y = ya, yb do into[y] = snapshot(0, y, W, 1) end end local STAGES = { backdrop, function() paint({}); rows(BASE, PIVY, 61) end, function() paint({ blink = true }); rows(PB, 19, 25) end, function() paint({ earL = true }); rows(PEL, 12, 18) end, function() paint({ earR = true }); rows(PER, 12, 18) end, function() paint({ tongue = true }); rows(PT, 31, 37) end, } local STAGE = 1 local STRAP, STRAPD = { 46, 140, 70 }, { 24, 92, 48 } local function strap(dx) for y = 5, 13 do local x = C - 1 + floor(dx * (y - 5) / 8 + 0.5) R(y == 5 and GOLD or STRAP, x, y, 3, 1) if y > 5 then R(STRAPD, x + 2, y, 1, 1) end end end local OM = 1.75 local function theta(t) if t < 0 then return 0 end local ramp = min(1, t / 2.5) ramp = ramp * ramp * (3 - 2 * ramp) local env = 0.45 + 0.55 * (0.5 + 0.5 * sin(0.27 * t)) return 0.017 * (cfg.sway or 3) * env * ramp * sin(OM * t) end local FL = {} for i = 1, 36 do local h = hash32(i * 0x9E3779B1) FL[i] = { x = umod(h, W), y0 = umod(h >> 8, 70), v = 5 + umod(h >> 14, 8), dr = 1 + umod(h >> 18, 20) / 10, ph = umod(h >> 22, 628) / 100, big = umod(h >> 26, 5) == 0 } end local BULB = { { 255, 80, 80 }, { 255, 210, 90 }, { 90, 220, 120 }, { 100, 170, 255 } } local function flakes(near, t) local n = (cfg.snow or 3) * 7 for i = 1, min(n, #FL) do local f = FL[i] if f.big == near then local y = (f.y0 + t * f.v) % (H + 6) - 3 local x = floor(f.x + f.dr * sin(t * 0.6 + f.ph) * 2 + 0.5) local iy = floor(y) local fr = y - iy local a = near and 0.95 or 0.55 if near then blend_rect(x, iy, 2, 1, 255, 255, 255, a * (1 - fr)); blend_rect(x, iy + 1, 2, 1, 255, 255, 255, a * fr) else blend(x, iy, 220, 232, 255, a * (1 - fr)); blend(x, iy + 1, 220, 232, 255, a * fr) end end end end function render() if STAGE <= #STAGES then if STAGE > 1 and BG then gfx.blit_rgb(BG, 0, 0, W, H) end STAGES[STAGE]() if BG then gfx.blit_rgb(BG, 0, 0, W, H) end STAGE = STAGE + 1 gfx.ready(false) return end local t = frame / FPS blit_rgb(BG, 0, 0, W, H) if cfg.lights ~= false then for i = 0, 7 do local x, y = 6 + 8 * i, 7 + (i % 2) local v = 0.5 + 0.5 * sin(t * 2.2 + i * 1.9) local b = BULB[i % 4 + 1] blend_rect(x - 1, y - 1, 3, 3, b[1], b[2], b[3], 0.25 + 0.3 * v) blend(x, y, b[1], b[2], b[3], 0.85 + 0.15 * v) end end flakes(false, t) local th = theta(t) local dx = floor(30 * th + 0.5) local blink = (t % 4.3) < 0.13 or (t % 11.7 > 5.5 and t % 11.7 < 5.63) local sT = t % 11 local tongue = cfg.tongue ~= false and sT > 6 and sT < 7.3 local earL = t % 7.7 > 3 and t % 7.7 < 3.35 local earR = (t + 2) % 8.3 < 0.35 strap(dx) for y = PIVY, 61 do local src = BASE[y] if blink and PB[y] then src = PB[y] elseif tongue and PT[y] then src = PT[y] elseif earL and PEL[y] then src = PEL[y] elseif earR and PER[y] then src = PER[y] end blit_rgb(src, dx, y, W, 1, KR, KG, KB) end local lag = 60 * (theta(t - 0.3) - th) local tipx = C + 8 + dx + lag local tipy = 8.6 + 0.4 * math.abs(lag) for dy = -2, 2 do for dx = -2, 2 do local d = sqrt((dx - (tipx - floor(tipx + 0.5))) ^ 2 + (dy - (tipy - floor(tipy + 0.5))) ^ 2) local a = min(1, 2.8 - d) if a > 0 then blend(floor(tipx + 0.5) + dx, floor(tipy + 0.5) + dy, 252, 252, 255, a) end end end flakes(true, t) end