info = { type = "image", title = "Cat toast", category = "food", author = "BRRRO", version = "1.0", license = "MIT", desc = "A cat-shaped toast with steam and a wink", api = 33, } local STEP_HZ = 30 local FR = 0 local ltr = ({ sk = { ["Topping"] = "Poleva", ["Butter"] = "Maslová", ["Jam"] = "Džem", ["Honey"] = "Medová", ["Wall colour"] = "Farba steny" }, cs = { ["Topping"] = "Poleva", ["Butter"] = "Máslová", ["Jam"] = "Džem", ["Honey"] = "Medová", ["Wall colour"] = "Barva stěny" }, })[lang] or {} local function LT(s) return ltr[s] or s end settings = { { key = "top", label = LT("Topping"), type = "int", default = 0, opts = { LT("Butter"), LT("Jam"), LT("Honey") } }, { key = "wall", label = LT("Wall colour"), type = "color", default = "#4674AA" }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local floor, ceil, sin, sqrt, min = math.floor, math.ceil, math.sin, math.sqrt, math.min local hash32, umod = math.hash32, math.umod local W, H = gfx.W, gfx.H local TAU = 6.2831853 local TAB_R, TAB_P, TAB_W = { 212, 58, 72 }, { 236, 150, 150 }, { 248, 238, 232 } local PLATE_E, PLATE, SHADOW = { 188, 196, 214 }, { 240, 243, 248 }, { 204, 208, 222 } local CRUST_D, CRUST = { 132, 66, 28 }, { 190, 114, 50 } local TOASTY, CRUMB, PORE = { 232, 180, 106 }, { 250, 222, 160 }, { 230, 192, 122 } local EYE, MOUTH = { 66, 36, 26 }, { 116, 60, 34 } local BLUSH, NOSE = { 248, 150, 140 }, { 232, 112, 112 } local TOPS = { [0] = { pat = { 250, 226, 120 }, hi = { 255, 248, 200 }, sh = { 224, 182, 68 }, melt = { 248, 204, 72 }, mhi = { 255, 238, 152 }, round = false }, [1] = { pat = { 196, 30, 62 }, hi = { 244, 98, 122 }, sh = { 138, 16, 44 }, melt = { 206, 38, 72 }, mhi = { 248, 120, 140 }, round = true }, [2] = { pat = { 242, 170, 40 }, hi = { 255, 218, 116 }, sh = { 198, 120, 22 }, melt = { 236, 156, 30 }, mhi = { 255, 208, 100 }, round = true }, } local WALL, WALL_DOT = { 70, 116, 170 }, { 92, 136, 186 } local BG = nil function on_settings() local c = cfg.wall or { r = 70, g = 116, b = 170 } WALL = { c.r, c.g, c.b } WALL_DOT = { c.r + (255 - c.r) // 6, c.g + (255 - c.g) // 6, c.b + (255 - c.b) // 6 } BG = nil end local function c3(c) return c[1], c[2], c[3] end local EARS = { { 13, 6, 10, 27 }, { 50, 6, 36, 53 } } local function head_span(y, d) local y0, y1 = 18 + d, 51 - d if y < y0 or y > y1 then return nil end local x0, x1, r = 10 + d, 53 - d, 9 - d if y > y1 - r then local dy = y - (y1 - r) - 0.5 local k = floor(r - sqrt(r * r - dy * dy) + 0.5) x0, x1 = x0 + k, x1 - k end return x0, x1 end local function ear_span(e, y, d) local tx, ty, b0, b1 = e[1], e[2] + d * 1.6, e[3] + d, e[4] - d if y < ty or y > 19 then return nil end local f = (y - ty) / (18 - ty) return floor(tx - (tx - b0) * f + 0.5), floor(tx + (b1 - tx) * f + 0.5) end local function toast_layer(d, c) for y = 6, 51 do local a, b = head_span(y, d) if a then rect(a, y, b - a + 1, 1, c3(c)) end for i = 1, 2 do a, b = ear_span(EARS[i], y, d) if a and b >= a then rect(a, y, b - a + 1, 1, c3(c)) end end end end local function ell(cx, cy, a, b, c) for y = floor(cy - b), ceil(cy + b) do local dy = (y + 0.5 - cy) / b if dy * dy < 1 then local hw = a * sqrt(1 - dy * dy) local x0, x1 = ceil(cx - hw - 0.5), floor(cx + hw - 0.5) if x1 >= x0 then rect(x0, y, x1 - x0 + 1, 1, c3(c)) end end end end local function build() rect(0, 0, W, 46, c3(WALL)) for y = 4, 40, 9 do for x = ((y // 9) % 2) * 5 + 2, W - 1, 10 do px(x, y, c3(WALL_DOT)) end end for r = 0, 4 do for c = 0, 15 do local col = (r % 2 == 0 and c % 2 == 0) and TAB_R or ((r + c) % 2 == 1 and TAB_P or TAB_W) rect(c * 4, 46 + r * 4, 4, 4, c3(col)) end end ell(32, 56, 29, 7.5, PLATE_E) ell(32, 55.5, 24, 5.5, PLATE) ell(33, 52, 22, 2.5, SHADOW) toast_layer(0, CRUST_D) toast_layer(1, CRUST) toast_layer(2, TOASTY) toast_layer(3, CRUMB) for i = 1, 2 do local e = EARS[i] for y = 13, 18 do local a, b = ear_span(e, y, 5) if a and b >= a then rect(a, y, b - a + 1, 1, c3(TOASTY)) end end end local n = 0 for i = 1, 90 do if n >= 26 then break end local h = hash32(i * 0x9E3779B1) local x, y = 15 + umod(h, 34), 21 + umod(h >> 8, 27) local face = y >= 30 and y <= 42 and x >= 16 and x <= 47 local a, b = head_span(y, 5) if a and x >= a and x <= b and not face then rect(x, y, 1 + ((h >> 16) & 1), 1, c3(PORE)); n = n + 1 end end rect(17, 38, 4, 2, c3(BLUSH)); rect(43, 38, 4, 2, c3(BLUSH)) rect(31, 36, 2, 1, c3(NOSE)) local M = { 29, 37, 30, 38, 31, 37, 32, 37, 33, 38, 34, 37 } for i = 1, #M, 2 do px(M[i], M[i + 1], c3(MOUTH)) end BG = gfx.snapshot(0, 0, W, H) end local function span(xl, xr, y, c) local a, b = floor(xl), floor(xr) local r, g, bl = c[1], c[2], c[3] if b > a then if b - a > 1 then rect(a + 1, y, b - a - 1, 1, r, g, bl) end blend(a, y, r, g, bl, a + 1 - xl) if xr > b then blend(b, y, r, g, bl, xr - b) end elseif xr > xl then blend(a, y, r, g, bl, xr - xl) end end local function puddle(cx, cy, R, c, hi) if R < 0.6 then return end local Ry = R * 0.5 for y = floor(cy - Ry), ceil(cy + Ry) do local dy = (y + 0.5 - cy) / Ry if dy * dy < 1 then local hw = R * sqrt(1 - dy * dy) span(cx - hw, cx + hw, y, c) end end if hi and R > 3 then rect(floor(cx - R * 0.55), floor(cy - Ry * 0.45), floor(R * 0.4), 1, c3(hi)) end end local function drip(x, y0, L, c, hi) if L < 0.3 then return end local li = floor(L); local f = L - li local r, g, b = c[1], c[2], c[3] if li > 0 then rect(x, y0, 2, li, r, g, b) end if li >= 2 then blend_rect(x - 1, y0 + li - 2, 4, 1, r, g, b, 1 - f) rect(x - 1, y0 + li - 1, 4, 1, r, g, b) if li >= 4 then px(x, y0 + li - 3, c3(hi)) end end blend_rect(li >= 2 and x - 1 or x, y0 + li, li >= 2 and 4 or 2, 1, r, g, b, f) end local function clamp01(v) return v < 0 and 0 or (v > 1 and 1 or v) end local P = 480 local SWX = { 26, 32, 38 } local function eye(x, mode) if mode == 0 then rect(x, 31, 3, 3, c3(EYE)); px(x + 2, 31, 255, 255, 255) elseif mode == 1 then rect(x, 32, 3, 1, c3(EYE)) else px(x, 33, c3(EYE)); px(x + 1, 32, c3(EYE)); px(x + 2, 33, c3(EYE)) end end function render() FR = frame * STEP_HZ // gfx.FPS if not BG then build() end gfx.blit_rgb(BG, 0, 0, W, H) local T = TOPS[cfg.top or 0] or TOPS[0] local bt, cyc = (FR + 50) % 140, ((FR + 50) // 140) % 4 local le, re = 0, 0 if bt < 4 or (cyc == 2 and bt >= 8 and bt < 12) then le, re = 1, 1 end if cyc == 1 and bt >= 60 and bt < 78 then re = 2 end eye(21, le); eye(40, re) if re == 2 then local a = sin((bt - 60) * 3.14159 / 18) px(46, 29, 255, 255, 255) blend(45, 29, 255, 255, 255, a); blend(47, 29, 255, 255, 255, a) blend(46, 28, 255, 255, 255, a); blend(46, 30, 255, 255, 255, a) end local t = (FR + 90) % P local by, h, sq, R, L1, L2 = 27, 0, 0, 0, 0, 0 local dropy, splat = nil, 0 if t < 16 then local k = t / 16 by, h = floor(-1 + 28 * k * k + 0.5), 7 elseif t < 24 then sq = sin(3.14159 * (t - 16) / 8); h = 7 - 2 * sq elseif t < 330 then local m = (t - 24) / 306 h = 7 * (1 - m) R = 2.5 + 7.5 * min(1, m / 0.75) L2 = 6 * clamp01((m - 0.5) / 0.3) L1 = 21 * clamp01((m - 0.62) / 0.38) elseif t < 420 then R, L1, L2 = 10, 21, 6 if t >= 340 and t < 352 then local k = (t - 340) / 12; dropy = floor(49 + 7 * k * k) end splat = 3 * clamp01((t - 352) / 14) else local a = 1 - (t - 420) / 60 R, L1, L2, splat = 10 * a, 21 * a, 6 * a, 3 * a end puddle(40, 26, R, T.melt, T.mhi) drip(47, 27, L1, T.melt, T.mhi) drip(33, 28, L2, T.melt, T.mhi) if dropy then rect(47, dropy, 2, 2, c3(T.melt)) end if splat > 0.2 then puddle(48, 56.5, splat, T.melt) end if h > 0.05 then local w = 9 + 2 * floor(sq + 0.5) local x0 = 35 - floor(sq + 0.5) local hf = floor(h); local f = h - hf local pr, pg, pb = c3(T.pat) if hf > 0 then rect(x0, by - hf, w, hf, pr, pg, pb) rect(x0 + w - 2, by - hf, 2, hf, c3(T.sh)) if T.round then rect(x0 + 1, by - hf, w - 2, 1, c3(T.hi)) else rect(x0, by - hf, w - 1, 1, c3(T.hi)) end end if f > 0.05 then if T.round then blend_rect(x0 + 2, by - hf - 1, w - 4, 1, pr, pg, pb, f) else blend_rect(x0, by - hf - 1, w, 1, pr, pg, pb, f) end end end local ph = (FR % 130) * 0.3 local sw = (FR % 90) * (TAU / 90) for i = 1, 3 do for y = 3, 16 do local p = ((16 - y) + ph + i * 4.7) % 13 if p < 8 then local a = 0.42 * sin(p * 0.3927) * (y - 2) / 14 if a > 0.03 then local x = SWX[i] + 1.4 * sin(y * 0.5 - sw + i * 2.1) local xi = floor(x); local fx = x - xi blend(xi, y, 250, 250, 255, a * (1 - fx)) blend(xi + 1, y, 250, 250, 255, a * fx) end end end end end