info = { type = "image", title = "Muffin face", category = "food", author = "BRRRO", version = "1.0", license = "MIT", desc = "Cupcake with a face blowing on its candle", api = 33, } local txl = ({ sk = { ["Icing"] = "Poleva", ["Wrapper"] = "Obal", ["Dripping"] = "Kvapkanie", ["Blows"] = "Fúkanie" }, cs = { ["Icing"] = "Poleva", ["Wrapper"] = "Obal", ["Dripping"] = "Kapání", ["Blows"] = "Foukání" }, })[lang] or {} local function TXL(s) return txl[s] or s end settings = { { key = "icing", label = TXL("Icing"), type = "color", default = "#FF9EC4" }, { key = "liner", label = TXL("Wrapper"), type = "color", default = "#F2C84B" }, { key = "melt", label = TXL("Dripping"), type = "int", min = 0, max = 3, default = 1 }, { key = "blow", label = TXL("Blows"), type = "bool", default = true }, } local rect, px, brect = gfx.rect, gfx.px, gfx.blend_rect local floor, ceil, sin, sqrt = math.floor, math.ceil, math.sin, math.sqrt local hash32, umod = math.hash32, math.umod local FPS = gfx.FPS local STEP_HZ = 30 local GRID, PAL = "", { 0, 0, 0 } local IC = { 255, 158, 196 } local DRIP = {} local function build() local ZERO = { 0 } do local n = 1 while n < 64 do table.move(ZERO, 1, n, n + 1); n = n * 2 end end local pal, pidx, cv = { 0, 0, 0 }, {}, {} for y = 1, 64 do cv[y] = table.move(ZERO, 1, 64, 1, {}) end local function C(r, g, b) r, g, b = floor(r + 0.5), floor(g + 0.5), floor(b + 0.5) r = r > 255 and 255 or r; g = g > 255 and 255 or g; b = b > 255 and 255 or b local k = r * 65536 + g * 256 + b local i = pidx[k] if not i then i = #pal // 3 pidx[k] = i local n = #pal pal[n + 1], pal[n + 2], pal[n + 3] = r, g, b end return i end local function fill(r, a, n, c) r[a] = c local k = 1 while k < n do local m = (k <= n - k) and k or (n - k) table.move(r, a, a + m - 1, a + k) k = k + m end end local function R(x, y, w, h, c) local xa, xb = (x < 0 and 0 or x), (x + w - 1 > 63 and 63 or x + w - 1) local ya, yb = (y < 0 and 0 or y), (y + h - 1 > 63 and 63 or y + h - 1) if xa > xb or ya > yb then return end local n = xb - xa + 1 local o = xa + 1 if n >= 12 then local r = cv[ya + 1] fill(r, o, n, c) for yy = ya + 2, yb + 1 do table.move(r, o, o + n - 1, o, cv[yy]) end else for yy = ya + 1, yb + 1 do local r = cv[yy] for i = o, o + n - 1 do r[i] = c end end end end local function E(cx, cy, rx, ry, c) for y = floor(cy - ry), ceil(cy + ry) - 1 do local dy = (y + 0.5 - cy) / ry local q = 1 - dy * dy if q >= 0 then local hw = rx * sqrt(q) local x0 = ceil(cx - hw - 0.5) R(x0, y, floor(cx + hw - 0.5) - x0 + 1, 1, c) end end end local function P(x, y, c) R(x, y, 1, 1, c) end local ic = cfg.icing or { r = 255, g = 158, b = 196 } local ln = cfg.liner or { r = 242, g = 200, b = 75 } IC = { ic.r, ic.g, ic.b } local ICE = C(ic.r, ic.g, ic.b) local ICE_L = C(ic.r * 1.1 + 12, ic.g * 1.1 + 12, ic.b * 1.1 + 12) local ICE_D = C(ic.r * 0.8, ic.g * 0.8, ic.b * 0.82) local LA, LB = C(ln.r, ln.g, ln.b), C(ln.r * 0.8, ln.g * 0.8, ln.b * 0.8) local LT = C(ln.r * 1.08 + 8, ln.g * 1.08 + 8, ln.b * 1.08 + 8) local WALL, TAB, TABE = C(30, 78, 96), C(94, 62, 70), C(132, 92, 100) local SP, SP_D = C(188, 122, 68), C(148, 90, 48) local CA, CB = C(255, 196, 60), C(255, 246, 210) R(0, 0, 64, 64, WALL) R(0, 59, 64, 5, TAB) R(0, 59, 64, 1, TABE) E(32.5, 60, 18, 2.5, C(66, 40, 52)) for y = 51, 59 do local k = (y - 51) / 8 local x0 = floor(16 + 4 * k + 0.5) local x1 = floor(47 - 4 * k + 0.5) for x = x0, x1 do P(x, y, ((x // 2) % 2 == 0) and LA or LB) end end R(15, 50, 34, 2, LT) E(32.5, 50, 19.5, 5.2, SP_D) E(32.5, 49.5, 19.5, 4.8, SP) R(14, 51, 36, 1, LT) E(32.5, 43, 18.5, 7, ICE_D) E(32.5, 42, 18.5, 7, ICE) E(26, 38, 5, 2.2, ICE_L) E(32.5, 35, 13.5, 5, ICE_D) E(32.5, 34, 13.5, 5, ICE) E(27, 32, 4, 1.8, ICE_L) E(32.5, 29, 9, 3.8, ICE_D) E(32.5, 28, 9, 3.8, ICE) E(29, 26.5, 3, 1.4, ICE_L) E(32.5, 24.5, 4, 3, ICE) P(32, 20, ICE); P(32, 21, ICE) P(22, 38, C(236, 60, 70)); P(23, 38, C(236, 60, 70)) P(41, 37, C(80, 170, 240)); P(42, 38, C(80, 170, 240)) P(28, 32, C(255, 220, 70)); P(29, 32, C(255, 220, 70)) P(37, 33, C(120, 220, 120)); P(38, 33, C(120, 220, 120)) P(35, 28, C(255, 255, 255)); P(30, 27, C(200, 120, 240)) for y = 12, 20 do R(31, y, 2, 1, ((y - 12) // 2) % 2 == 0 and CA or CB) end DRIP = {} for i, x in ipairs({ 16, 26, 39, 47 }) do local dx = (x - 32.5) / 18.5 DRIP[i] = { x, floor(43 + 7 * sqrt(1 - dx * dx) - 0.5) } end local rows = {} for y = 0, 63 do rows[y + 1] = string.char(table.unpack(cv[y + 1], 1, 64)) end GRID = table.concat(rows) PAL = pal end function on_settings() build() end local EYE = { 30, 16, 26 } local P9 = 9 * STEP_HZ local function flame(t, blow) local cx, ty = 31, 12 local a = t * 0.35 local s = sin(a) + 0.6 * sin(a * 2.3 + 1.1) local tall = sin(a * 1.9 + 2) > 0.2 and 5 or 4 local lean = s > 0.7 and 1 or (s < -0.7 and -1 or 0) if blow then tall = 3; lean = -1 end local fy = ty - 2 local ga = 0.07 + 0.03 * (tall - 3) brect(cx - 2, fy - 2, 6, 5, 255, 170, 60, ga) brect(cx - 1, fy - 3, 4, 7, 255, 170, 60, ga) rect(cx, ty - tall, 2, tall, 255, 128, 24) rect(cx, ty - 3, 2, 2, 255, 214, 70) px(cx + (lean > 0 and 1 or 0), ty - 2, 255, 250, 210) local tx = lean < 0 and cx - 1 or (lean > 0 and cx + 2 or cx + (t // 7) % 2) px(tx, ty - tall - 1, 255, 196, 60) if blow then px(cx - 2, ty - tall, 255, 180, 60) end end function render() local t = frame * STEP_HZ // FPS gfx.blit_indexed(GRID, PAL, 0, 0, 64, 64, 64, 64) local ph = t % P9 local blow = cfg.blow ~= false and ph >= 210 and ph < 255 local grin = ph >= 150 and ph < 180 local melt = cfg.melt or 1 if melt > 0 then local T = 540 // melt for i = 1, #DRIP do local d = DRIP[i] local p = (t + i * (T // 4)) % T local len if p < T - 24 then len = 2 + floor(4 * (p / (T - 24)) + 0.5) elseif p < T - 12 then len = 6 else len = 2 end rect(d[1], d[2] - 1, 2, len, IC[1], IC[2], IC[3]) if len > 3 then rect(d[1] - 1, d[2] + len - 3, 4, 2, IC[1], IC[2], IC[3]) end if p >= T - 12 then local q = p - (T - 12) local y = d[2] + 4 + 0.07 * q * q if y < 59 then rect(d[1], floor(y), 2, 2, IC[1], IC[2], IC[3]) end end end end local shut = blow or (t + 40) % 110 < 3 if shut then rect(23, 42, 3, 1, EYE[1], EYE[2], EYE[3]); rect(38, 42, 3, 1, EYE[1], EYE[2], EYE[3]) else rect(24, 41, 2, 3, EYE[1], EYE[2], EYE[3]); rect(39, 41, 2, 3, EYE[1], EYE[2], EYE[3]) px(24, 41, 255, 255, 255); px(39, 41, 255, 255, 255) end brect(19, 44, 3, 2, 255, 120, 140, 0.7); brect(43, 44, 3, 2, 255, 120, 140, 0.7) if blow then rect(32, 46, 2, 2, EYE[1], EYE[2], EYE[3]) elseif grin then rect(30, 46, 5, 2, EYE[1], EYE[2], EYE[3]) rect(31, 47, 3, 1, 255, 100, 120) else rect(30, 47, 5, 1, EYE[1], EYE[2], EYE[3]); px(29, 46, EYE[1], EYE[2], EYE[3]); px(35, 46, EYE[1], EYE[2], EYE[3]) end flame(t, blow) local k = t // 18 for i = 1, 2 do local h = hash32(k * 131 + i * 0x9E3779B1) local a = (t - k * 18) + umod(h >> 4, 6) if a < 18 then local x = 28 + umod(h >> 8, 9) brect(x, floor(7 - a * 0.3), 1, 1, 255, 230, 120, 1 - a / 18) end end local sp = t % 120 if sp < 6 then if sp >= 2 and sp < 4 then rect(24, 38, 3, 1, 255, 255, 255); rect(25, 37, 1, 3, 255, 255, 255) else px(25, 38, 255, 255, 255) end end end