info = { type = "image", title = "Glasshouse cat", category = "animals", author = "BRRRO", version = "1.0", license = "MIT", desc = "A black cat naps among dripping plants", api = 44, } local tr = ({ sk = { ["Drips"] = "Kvapky", ["Butterfly"] = "Motýľ", ["Wings"] = "Krídla" }, cs = { ["Drips"] = "Kapky", ["Butterfly"] = "Motýl", ["Wings"] = "Křídla" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "drips", label = T("Drips"), type = "int", min = 0, max = 3, default = 3 }, { key = "fly", label = T("Butterfly"), type = "bool", default = true }, { key = "wing", label = T("Wings"), type = "color", default = "#F08C28" }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sin, sqrt, exp = math.floor, math.sin, math.sqrt, math.exp local W, H, FPS = gfx.W, gfx.H, gfx.FPS local CYC = 600 local OMEGA = 6 * 6.28318 / (CYC / FPS) local function rgb(r, g, b) return floor(r + 0.5), floor(g + 0.5), floor(b + 0.5) end local GREENS = { { 40, 114, 58 }, { 58, 146, 68 }, { 78, 174, 82 }, { 28, 88, 50 } } local RIB = { 22, 70, 42 } local function leaf(cx, cy, rx, ry, slope, gi) local c = GREENS[gi] for dx = -rx, rx do local half = floor(ry * sqrt(1 - (dx / (rx + 0.5)) ^ 2) + 0.5) local yc = cy + floor(slope * dx + 0.5) rect(cx + dx, yc - half, 1, 2 * half + 1, c[1], c[2], c[3]) if half > 0 then px(cx + dx, yc - half, c[1] + 30, c[2] + 34, c[3] + 24) end px(cx + dx, yc, RIB[1], RIB[2], RIB[3]) end end local function pot(x, y, w, h) rect(x, y, w, 2, 214, 124, 78); rect(x + 1, y + 2, w - 2, h - 2, 184, 98, 60); rect(x + 1, y + 2, 1, h - 2, 214, 124, 78) rect(x + w - 2, y + 2, 1, h - 2, 142, 74, 48) end local BG, PART, STAGE = nil, nil, 1 local function room() for y = 0, H - 1 do local t = y / (H - 1) local r, g, b if t < 0.5 then r, g, b = 214 - 62 * t * 2, 236 - 36 * t * 2, 178 - 56 * t * 2 else r, g, b = 152 - 62 * (t - 0.5) * 2, 200 - 60 * (t - 0.5) * 2, 122 - 40 * (t - 0.5) * 2 end rect(0, y, W, 1, rgb(r, g, b)) end for y = 0, H - 1 do blend_rect(floor(52 - y * 0.75), y, 16, 1, 255, 238, 150, 0.14) end for _, x in ipairs({ 21, 42 }) do rect(x, 0, 1, 54, 112, 154, 104); rect(x + 1, 0, 1, 54, 236, 248, 210) end for _, y in ipairs({ 14, 34 }) do rect(0, y, W, 1, 112, 154, 104); rect(0, y + 1, W, 1, 236, 248, 210) end end local function plants() pot(50, 52, 11, 10); pot(30, 54, 10, 8); pot(42, 57, 6, 5) rect(55, 22, 2, 30, 30, 92, 50); rect(34, 40, 2, 14, 30, 92, 50) local L = { { 50, 44, 6, 3, -0.30, 1 }, { 61, 42, 5, 3, 0.35, 2 }, { 49, 34, 6, 3, -0.35, 3 }, { 60, 32, 5, 3, 0.40, 1 }, { 51, 25, 5, 3, -0.40, 2 }, { 59, 20, 5, 3, 0.35, 3 }, { 55, 13, 5, 3, -0.20, 1 }, { 62, 50, 4, 2, 0.30, 4 }, { 29, 46, 5, 3, -0.50, 2 }, { 39, 46, 5, 3, 0.50, 3 }, { 34, 40, 4, 3, -0.20, 1 }, { 27, 52, 4, 2, -0.30, 3 }, { 44, 52, 4, 2, 0.30, 2 }, { 46, 53, 3, 2, -0.40, 4 }, } for _, l in ipairs(L) do leaf(l[1], l[2], l[3], l[4], l[5], l[6]) end for _, x in ipairs({ 44, 47, 62 }) do for y = 0, 10 + (x % 5) * 3 do px(x + (y // 4 % 2), y, 40, 108, 56) end px(x + 1, 6, 78, 174, 82); px(x - 1, 11, 78, 174, 82) end leaf(62, 62, 6, 3, -0.50, 4); leaf(46, 63, 5, 2, 0.30, 4) end local CAT, RIMC, CRATE = { 18, 16, 22 }, { 70, 62, 66 }, nil local function cat() rect(0, 56, 27, 8, 136, 92, 54); rect(0, 56, 27, 1, 176, 126, 76); rect(0, 59, 27, 1, 108, 70, 42); rect(0, 62, 27, 2, 108, 70, 42) rect(9, 56, 1, 8, 108, 70, 42); rect(18, 56, 1, 8, 108, 70, 42) rect(3, 49, 17, 7, CAT[1], CAT[2], CAT[3]); rect(5, 47, 13, 2, CAT[1], CAT[2], CAT[3]); rect(4, 48, 15, 1, CAT[1], CAT[2], CAT[3]) rect(14, 43, 9, 8, CAT[1], CAT[2], CAT[3]) rect(14, 41, 2, 2, CAT[1], CAT[2], CAT[3]); rect(21, 41, 2, 2, CAT[1], CAT[2], CAT[3]) px(15, 42, 84, 54, 64); px(22, 42, 84, 54, 64) rect(2, 54, 15, 2, CAT[1], CAT[2], CAT[3]) rect(5, 47, 9, 1, RIMC[1], RIMC[2], RIMC[3]); rect(15, 43, 7, 1, RIMC[1], RIMC[2], RIMC[3]); px(14, 41, RIMC[1], RIMC[2], RIMC[3]); px(21, 41, RIMC[1], RIMC[2], RIMC[3]) rect(18, 48, 1, 2, RIMC[1], RIMC[2], RIMC[3]) rect(3, 49, 1, 4, 44, 40, 48); rect(16, 54, 2, 1, 110, 100, 100) rect(16, 46, 2, 1, 94, 86, 74); rect(19, 46, 2, 1, 94, 86, 74) px(18, 48, 120, 70, 80) end local STAGES = { room, plants, cat } local function build() if STAGE > 1 then gfx.blit_rgb(PART, 0, 0, W, H) end STAGES[STAGE]() STAGE = STAGE + 1 if STAGE <= #STAGES then PART = gfx.snapshot(0, 0, W, H) else BG = gfx.snapshot(0, 0, W, H) end end local function seg(c, a, b) if c <= a then return 0 elseif c >= b then return 1 end return (c - a) / (b - a) end local function frect(x, y, w, h, r, g, b) local x0 = floor(x) local f = x - x0 if f < 0.05 then rect(x0, y, w, h, r, g, b) return end blend_rect(x0, y, 1, h, r, g, b, 1 - f) if w > 1 then rect(x0 + 1, y, w - 1, h, r, g, b) end blend_rect(x0 + w, y, 1, h, r, g, b, f) end local HX, HY, CL = 28, 0, 22 local function theta(c) local gust = sin(3.14159 * seg(c, 240, 420)) ^ 2 return (0.055 + 0.05 * gust) * sin(c / FPS * OMEGA) end local function hanging(c) local th = theta(c) local sx = HX + CL * sin(th) local sy = HY + floor(CL * (1 - th * th * 0.5) + 0.5) local px0 = sx - 5 for k = 1, 10 do local u = k / 11 frect(HX + (sx - HX) * u, floor(HY + (sy - HY) * u), 1, 1, 170, 170, 160) end for j = 0, 2 do local x = px0 + 1 + j * 3 for k = 1, 3 do local lagx = x + (theta(c - 4 * k - j) - th) * CL * 1.2 frect(lagx, sy + 6 + (k - 1) * 3 + j % 2, 1, 3, 48 + k * 8, 140 + k * 6, 62) end end frect(px0, sy, 11, 2, 214, 124, 78) frect(px0 + 1, sy + 2, 9, 4, 184, 98, 60) frect(px0 + 1, sy + 2, 1, 4, 214, 124, 78) frect(px0 + 8, sy + 2, 1, 4, 142, 74, 48) frect(px0 + 1, sy - 3, 9, 3, 58, 146, 68) frect(px0 + 3, sy - 5, 5, 2, 78, 174, 82) frect(px0, sy - 1, 2, 2, 40, 114, 58); frect(px0 + 9, sy - 1, 2, 2, 40, 114, 58) end local DR = { { 56, 24, 38, 130, 0 }, { 36, 43, 53, 170, 60 }, { 52, 35, 49, 210, 100 } } local G = 0.14 local function drips(n, c) for i = 1, n do local d = DR[i] local p = (c + d[5]) % d[4] if p < 36 then local a = 0.35 + 0.65 * p / 36 blend_rect(d[1], d[2], 1, 1, 206, 238, 255, a) if p > 18 then blend_rect(d[1], d[2] + 1, 1, 1, 206, 238, 255, (p - 18) / 36) end else local t = p - 36 local y = d[2] + 1 + 0.5 * G * t * t if y < d[3] then rect(d[1], floor(y), 1, 2, 206, 238, 255) elseif y < d[3] + 40 and t < 80 then local k = floor(sqrt(2 * (d[3] - d[2]) / G)) local s = t - k if s >= 0 and s < 5 then local a = 0.7 * (1 - s / 5) blend_rect(d[1] - 1 - s // 2, d[3] - 1, 1, 1, 206, 238, 255, a) blend_rect(d[1] + 1 + s // 2, d[3] - 1, 1, 1, 206, 238, 255, a) blend_rect(d[1], d[3] - 2 - s // 3, 1, 1, 206, 238, 255, a) end end end end end local function butterfly(c, wc) if c < 150 or c > 330 then return end local u = seg(c, 150, 330) local x = 70 - 78 * u local y = 33 + 5 * sin(u * 14) + 5 * u local up = (c // 3) % 2 == 0 local r, g, b = wc.r, wc.g, wc.b local yi = floor(y + 0.5) frect(x, yi - (up and 2 or 0), 2, 2, r, g, b) frect(x + 3, yi - (up and 2 or 0), 2, 2, r, g, b) frect(x + 2, yi - 1, 1, 3, 30, 24, 20) if up then frect(x, yi - 2, 1, 1, 30, 24, 20) end end function render() if not BG then build() if not BG then gfx.ready(false) return end end gfx.blit_rgb(BG, 0, 0, W, H) local c = (frame + 130) % CYC hanging(c) drips(cfg.drips or 3, c) local fly = cfg.fly ~= false if fly then butterfly(c, cfg.wing or { r = 240, g = 140, b = 40 }) end if fly and c >= 236 and c < 400 then local h = (c < 239 or c >= 397) and 1 or 2 rect(19, 46 - h + 1, 2, h, 250, 214, 40) if h == 2 then rect(20, 45, 1, 2, 20, 16, 10) end end end