info = { type = "image", title = "Witch cat", category = "holidays", author = "BRRRO", version = "1.0", license = "MIT", desc = "Black cat in a witch hat on a glowing pumpkin", api = 33, } local tr = ({ sk = { ["Pumpkin light"] = "Svetlo tekvice", ["Bats"] = "Netopiere" }, cs = { ["Pumpkin light"] = "Světlo dýně", ["Bats"] = "Netopýři" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "glow", label = T("Pumpkin light"), type = "color", default = "#FFB43C" }, { key = "bats", label = T("Bats"), type = "int", min = 0, max = 3, default = 1 }, } local rect, px, blend = gfx.rect, gfx.px, gfx.blend local floor, sin, cos, sqrt = math.floor, math.sin, math.cos, math.sqrt local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local TAU = 6.28318 local function c3(c) return c[1], c[2], c[3] end local SKY, SKY_LO = { 78, 54, 132 }, { 150, 92, 150 } local MOON, MOON_D = { 252, 230, 160 }, { 222, 196, 128 } local HALO1, HALO2 = { 118, 90, 172 }, { 98, 72, 154 } local STAR = { 236, 226, 255 } local GROUND, G_RIM = { 54, 40, 82 }, { 120, 92, 162 } local PUMP, PUMP_D = { 236, 124, 38 }, { 196, 90, 28 } local PUMP_L, PUMP_O = { 255, 172, 84 }, { 116, 46, 18 } local CAT, CAT_L = { 40, 34, 58 }, { 72, 62, 98 } local RIM = { 116, 100, 168 } local EYE, PUPIL = { 228, 216, 74 }, { 28, 20, 30 } local NOSE, WHISK = { 222, 120, 160 }, { 150, 140, 188 } local HAT, HAT_L = { 58, 38, 90 }, { 104, 76, 152 } local HAT_O, BAND = { 26, 18, 40 }, { 196, 70, 152 } local BUCKLE = { 244, 204, 90 } local BAT = { 28, 20, 38 } local MX, MY, MR = 12, 11, 7 local GYc = {} for x = 0, W - 1 do GYc[x] = floor(56 + 1.5 * sin(x * 0.11 + 0.7) + 0.5) end local SPANS = {} do local head = { 6, 7, 8, 9, 9, 9, 9, 9, 9, 8, 7 } for i = 1, #head do SPANS[#SPANS + 1] = { 18 + i, 32 - head[i], 32 + head[i] } end local body = { 7, 8, 8, 9, 10, 10, 10, 10, 10, 10, 10, 9 } for i = 1, #body do SPANS[#SPANS + 1] = { 29 + i, 32 - body[i], 32 + body[i] } end local ears = { { 13, 23, 23 }, { 14, 23, 24 }, { 15, 22, 24 }, { 16, 22, 25 }, { 17, 22, 25 }, { 18, 23, 25 } } for i = 1, #ears do local e = ears[i] SPANS[#SPANS + 1] = e SPANS[#SPANS + 1] = { e[1], 64 - e[3], 64 - e[2] } end end local HATR = { { 0, 41, 42 }, { 1, 39, 41 }, { 2, 36, 40 }, { 3, 34, 38 }, { 4, 32, 37 }, { 5, 31, 36 }, { 6, 30, 35 }, { 7, 29, 35 }, { 8, 29, 36 }, { 9, 28, 36 }, { 10, 28, 37 }, { 11, 27, 37 }, { 12, 27, 38 }, { 13, 26, 38 }, { 14, 26, 38 }, { 15, 25, 39 }, { 16, 25, 39 }, { 17, 21, 43 }, { 18, 19, 45 }, } local FACE = { { 44, 25, 25 }, { 45, 24, 26 }, { 46, 23, 27 }, { 44, 39, 39 }, { 45, 38, 40 }, { 46, 37, 41 }, { 48, 32, 32 }, { 49, 31, 33 }, { 51, 22, 23 }, { 51, 41, 42 }, { 52, 22, 42 }, { 53, 23, 41 }, { 54, 25, 39 }, { 55, 28, 36 }, } local TEETH = { { 52, 27, 28 }, { 52, 36, 37 }, { 55, 31, 33 } } local BG = nil local function pump_hw(y) local dy = (y - 50) / 11.5 if dy * dy >= 1 then return -1 end return floor(17 * sqrt(1 - dy * dy) + 0.5) end local function build_bg() local G0, G1 = 38, 52 rect(0, 0, W, G0, c3(SKY)) for y = G0, G1 - 1 do local t = (y - G0 + 1) / (G1 - G0 + 1) rect(0, y, W, 1, floor(SKY[1] + (SKY_LO[1] - SKY[1]) * t + 0.5), floor(SKY[2] + (SKY_LO[2] - SKY[2]) * t + 0.5), floor(SKY[3] + (SKY_LO[3] - SKY[3]) * t + 0.5)) end rect(0, G1, W, H - G1, c3(SKY_LO)) for y = MY - MR - 5, MY + MR + 5 do for x = MX - MR - 5, MX + MR + 5 do local dx, dy = x - MX, y - MY local d2 = dx * dx + dy * dy if d2 <= (MR + 0.5) * (MR + 0.5) then px(x, y, c3(MOON)) elseif d2 <= (MR + 2.5) * (MR + 2.5) then px(x, y, c3(HALO1)) elseif d2 <= (MR + 4.5) * (MR + 4.5) then px(x, y, c3(HALO2)) end end end px(MX - 2, MY - 3, c3(MOON_D)); px(MX - 3, MY - 3, c3(MOON_D)); px(MX + 2, MY + 1, c3(MOON_D)) px(MX - 1, MY + 3, c3(MOON_D)); px(MX + 3, MY - 2, c3(MOON_D)) for x = 0, W - 1 do rect(x, GYc[x], 1, H - GYc[x], c3(GROUND)); px(x, GYc[x], c3(G_RIM)) end for pass = 1, 2 do for y = 39, 61 do local hw = pump_hw(y) if hw >= 0 then if pass == 1 then rect(32 - hw - 1, y - 1, 2 * hw + 3, 3, c3(PUMP_O)) else rect(32 - hw, y, 2 * hw + 1, 1, c3(PUMP)) end end end end for y = 40, 60 do local hw = pump_hw(y) if hw > 2 then px(floor(32 - hw * 0.62 + 0.5), y, c3(PUMP_D)); px(floor(32 + hw * 0.62 + 0.5), y, c3(PUMP_D)) px(floor(32 - hw * 0.22 + 0.5), y, c3(PUMP_D)); px(floor(32 + hw * 0.22 + 0.5), y, c3(PUMP_D)) if y >= 42 and y <= 50 then px(32 - hw + 2, y, c3(PUMP_L)) end end end for i = 1, #FACE do local s = FACE[i] rect(s[2] - 1, s[1], s[3] - s[2] + 3, 1, c3(PUMP_D)) end for i = 1, #SPANS do local s = SPANS[i] rect(s[2] - 1, s[1] - 1, s[3] - s[2] + 3, 3, c3(HAT_O)) end for i = 1, #SPANS do local s = SPANS[i] rect(s[2], s[1], s[3] - s[2] + 1, 1, c3(CAT)) if s[2] < 32 then px(s[2], s[1], c3(RIM)) end end rect(23, 15, 1, 2, c3(CAT_L)); rect(40, 15, 1, 2, c3(CAT_L)) rect(25, 39, 5, 3, c3(CAT_L)); rect(35, 39, 5, 3, c3(CAT_L)) px(27, 41, c3(CAT)); px(37, 41, c3(CAT)) px(32, 31, c3(CAT_L)); rect(31, 32, 3, 1, c3(CAT_L)); px(32, 33, c3(CAT_L)) px(32, 26, c3(NOSE)); px(31, 27, c3(CAT_L)); px(33, 27, c3(CAT_L)) rect(19, 26, 4, 1, c3(WHISK)); rect(20, 28, 3, 1, c3(WHISK)) rect(42, 26, 4, 1, c3(WHISK)); rect(42, 28, 3, 1, c3(WHISK)) for i = 1, #HATR do local s = HATR[i] rect(s[2] - 1, s[1] - 1, s[3] - s[2] + 3, 3, c3(HAT_O)) end for i = 1, #HATR do local s = HATR[i] rect(s[2], s[1], s[3] - s[2] + 1, 1, c3(HAT)) px(s[2], s[1], c3(HAT_L)) end rect(25, 14, 14, 3, c3(BAND)); rect(26, 14, 1, 1, c3(HAT)); px(25, 15, c3(HAT_L)) rect(30, 13, 5, 5, c3(BUCKLE)); rect(31, 14, 3, 3, c3(HAT)) rect(20, 17, 6, 1, c3(HAT_L)) for i = 1, 12 do local h = hash32(i * 0x9E3779B1) local x, y = umod(h, W), umod(h >> 8, 34) local dx, dy = x - MX, y - MY if dx * dx + dy * dy > 150 and (x < 17 or x > 47 or y > 20) then px(x, y, c3(STAR)) end end BG = gfx.snapshot(0, 0, W, H) end local GL = { { 255, 220, 140 }, { 255, 180, 60 }, { 220, 130, 40 } } function on_settings() local c = cfg.glow or { r = 255, g = 180, b = 60 } GL[1] = { c.r + (255 - c.r) * 45 // 100, c.g + (255 - c.g) * 45 // 100, c.b + (255 - c.b) * 45 // 100 } GL[2] = { c.r, c.g, c.b } GL[3] = { c.r * 86 // 100, c.g * 70 // 100, c.b * 60 // 100 } end local function face(t) local lv = umod(hash32((t // 3) * 0x9E3779B1 + 0x1234), 6) local c = (lv < 2) and GL[1] or (lv < 5 and GL[2] or GL[3]) for i = 1, #FACE do local s = FACE[i] rect(s[2], s[1], s[3] - s[2] + 1, 1, c3(c)) end local core = (lv == 5) and GL[2] or GL[1] rect(28, 53, 9, 1, c3(core)); px(25, 46, c3(core)); px(39, 46, c3(core)) for i = 1, #TEETH do local s = TEETH[i] rect(s[2], s[1], s[3] - s[2] + 1, 1, c3(PUMP)) end end local function eyes(t) if t % 113 >= 70 and t % 113 < 74 then rect(27, 24, 3, 1, c3(RIM)); rect(35, 24, 3, 1, c3(RIM)) else rect(27, 23, 3, 3, c3(EYE)); rect(35, 23, 3, 3, c3(EYE)) rect(28, 23, 1, 3, c3(PUPIL)); rect(36, 23, 1, 3, c3(PUPIL)) px(27, 23, 255, 255, 230); px(35, 23, 255, 255, 230) end end local function swish(u) if u < 0 or u >= 45 then return 0 end local env = u / 5 if env > 1 then env = 1 end local e2 = (45 - u) / 12 if e2 < env then env = e2 end return 0.6 * env * sin(u * TAU / 15) end local NT = 14 local function tail(t) local u = (t - 178) % 150 local x, y = 41.0, 39.0 local a = -0.3 for s = 1, NT do a = a - 0.13 local d = swish(u - 1.5 * (s - 1)) * (0.3 + 0.06 * s) x = x + 1.3 * cos(a + d) y = y + 1.3 * sin(a + d) local ix, iy = floor(x + 0.5), floor(y + 0.5) rect(ix - 1, iy - 1, 2, 2, c3(CAT)) if s > 2 then px(ix - 1, iy - 1, c3(CAT_L)) end end end local BODY = { { -2, 0, 0 }, { -2, 1, 1 }, { -1, 0, 1 }, { 0, 0, 1 } } local POSE = { { { -3, -4, -4 }, { -2, -3, -2 }, { -1, -2, -1 } }, { { -2, -5, -5 }, { -1, -4, -1 } }, { { 0, -2, -1 }, { 1, -3, -3 }, { 2, -4, -4 } }, } local ORDER = { 1, 2, 3, 2 } local function run(ix, f, y, a, b) blend(ix + a, y, BAT[1], BAT[2], BAT[3], 1 - f) if b > a then rect(ix + a + 1, y, b - a, 1, c3(BAT)) end blend(ix + b + 1, y, BAT[1], BAT[2], BAT[3], f) end local function bat(t, i) local w = TAU / 260 local ph = i * 2.1 local x = 31.5 + 26 * sin(t * w + ph) local y = floor(9 + 4 * sin(2 * (t * w + ph)) + (i - 1) * 4 + 0.5) local ix = floor(x) local f = x - ix for k = 1, #BODY do local s = BODY[k]; run(ix, f, y + s[1], s[2], s[3]) end local p = POSE[ORDER[(t // 3 + i) % 4 + 1]] for k = 1, #p do local s = p[k] run(ix, f, y + s[1], s[2], s[3]) run(ix, f, y + s[1], 1 - s[3], 1 - s[2]) end end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local t = frame * STEP_HZ // FPS face(t) eyes(t) tail(t) for i = 1, (cfg.bats or 1) do bat(t, i) end end