info = { type = "image", title = "Lazy cat", category = "animals", author = "BRRRO", version = "1.0", license = "MIT", desc = "A lazy white cat naps in a meadow", api = 33, } local tr = ({ sk = { ["Butterfly"] = "Motýľ" }, cs = { ["Butterfly"] = "Motýl" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "fly", label = T("Butterfly"), type = "bool", default = true }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local floor, sin = math.floor, math.sin 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 rep = string.rep local function c3(c) return c[1], c[2], c[3] end local function art(rows, keys) local map = { ["."] = 0 } for i = 1, #keys do map[keys:sub(i, i)] = i end local w = 0 for i = 1, #rows do for _, seg in ipairs(rows[i]) do if seg[1] + #seg[2] > w then w = seg[1] + #seg[2] end end end local out = {} for i = 1, #rows do local r = {} for x = 1, w do r[x] = 0 end for _, seg in ipairs(rows[i]) do for k = 1, #seg[2] do r[seg[1] + k] = map[seg[2]:sub(k, k)] end end out[i] = string.char(table.unpack(r, 1, w)) end return table.concat(out), w, #rows end local OUT = { 96, 100, 124 } local WH = { 246, 246, 250 } local SH = { 200, 206, 226 } local PINK = { 240, 150, 172 } local EYE = { 40, 40, 60 } local function Wn(n) return rep("w", n) end local function On(n) return rep("o", n) end local CAT, CW, CH = art({ { { 13, On(10) } }, { { 10, "ooo" .. Wn(10) .. "ooo" } }, { { 8, "oo" .. Wn(16) .. "oo" } }, { { 7, "o" .. Wn(20) .. "o" } }, { { 6, "o" .. Wn(22) .. "o" } }, { { 5, "o" .. Wn(24) } }, { { 5, "o" .. Wn(24) } }, { { 4, "o" .. Wn(25) } }, { { 4, "o" .. Wn(25) } }, { { 4, "o" .. Wn(25) } }, { { 4, "o" .. Wn(6) .. "s" .. Wn(18) } }, { { 4, "o" .. Wn(5) .. "s" .. Wn(19) } }, { { 4, "o" .. Wn(5) .. "s" .. Wn(23) }, { 34, On(17) } }, { { 4, "o" .. Wn(5) .. "s" .. Wn(38) .. "po" } }, { { 4, "o" .. Wn(6) .. rep("s", 24) .. "o" .. Wn(13) .. "po" } }, { { 4, On(47) } }, }, "owspe") local CPAL = { 0, 0, 0, OUT[1], OUT[2], OUT[3], WH[1], WH[2], WH[3], SH[1], SH[2], SH[3], PINK[1], PINK[2], PINK[3], EYE[1], EYE[2], EYE[3] } local CX, CY = 6, 36 local HEAD, HW, HH = art({ { { 0, "....oo..........oo...." } }, { { 0, "...opwo.oooooo.owpo..." } }, { { 0, "...opwwowwwwwwowwpo..." } }, { { 0, "...owwwwwwwwwwwwwwo..." } }, { { 0, "..owwwwwwwwwwwwwwwwo.." } }, { { 0, ".owwwwwwwwwwwwwwwwwwo." } }, { { 0, ".owwwwwewwwwwwwewwwwo." } }, { { 0, "owwwwweewwwwwweewwwwwo" } }, { { 0, "owwwwweewwwwwweewwwwwo" } }, { { 0, "owwwwwwwwwppwwwwwwwwwo" } }, { { 0, "owwwwwwwwowwowwwwwwwwo" } }, { { 0, ".owwwwwwwwoowwwwwwwwo." } }, { { 0, "..oowwwwwwwwwwwwwwoo.." } }, { { 0, "....oooooooooooooo...." } }, }, "owspe") local HX, HY = CX + 26, CY - 2 local SKY, CLOUD = { 150, 208, 240 }, { 236, 244, 252 } local HILL = { 120, 186, 104 } local MEAD, MEAD_D = { 104, 176, 74 }, { 82, 152, 60 } local BLADE = { 56, 126, 46 } local FLOWERS = { { 3, 34, 1 }, { 22, 31, 2 }, { 59, 32, 3 }, { 60, 57, 1 }, { 2, 58, 2 } } local FCOL = { { 252, 252, 252 }, { 255, 210, 60 }, { 246, 140, 190 } } local BG = nil local function build_bg() rect(0, 0, W, H, c3(SKY)) rect(5, 6, 14, 3, c3(CLOUD)); rect(8, 5, 7, 1, c3(CLOUD)) rect(38, 11, 11, 2, c3(CLOUD)); rect(40, 10, 5, 1, c3(CLOUD)) rect(0, 28, W, H - 28, c3(MEAD)) for x = 0, W - 1 do local top = floor(23 + 2 * sin(x * 0.13) + 1.5 * sin(x * 0.41 + 1) + 0.5) rect(x, top, 1, 29 - top, c3(HILL)) end for i = 0, 27 do local h = hash32(i * 0x9E3779B1 + 5) local x, y = umod(h, W), 31 + umod(h >> 8, 32) px(x, y, c3(MEAD_D)); px(x - 1, y - 1, c3(MEAD_D)); px(x + 1, y - 1, c3(MEAD_D)) end for i = 1, #FLOWERS do local f = FLOWERS[i] local c = FCOL[f[3]] rect(f[1] - 1, f[2], 3, 1, c3(c)); rect(f[1], f[2] - 1, 1, 3, c3(c)) px(f[1], f[2], 255, 190, 40) end blend_rect(CX + 5, CY + 15, 46, 2, 40, 96, 30, 0.35) gfx.blit_indexed(CAT, CPAL, CX, CY, CW, CH, CW, CH, true) gfx.blit_indexed(HEAD, CPAL, HX, HY, HW, HH, HW, HH, true) BG = gfx.snapshot(0, 0, W, H) end local function blink(t) if t % 110 < 4 then for _, ex in ipairs({ HX + 6, HX + 14 }) do rect(ex, HY + 6, 2, 3, c3(WH)) rect(ex, HY + 7, 2, 1, c3(OUT)) end end end local function tail(t) local u = (t + 40) % 150 local L = 0 if u < 8 then L = 7 * u / 8 elseif u < 20 then L = 7 elseif u < 28 then L = 7 * (28 - u) / 8 elseif u < 32 then L = u - 28 elseif u < 36 then L = 36 - u end local x0, y0 = CX + 4, CY + 13 for k = 0, 10 do local f = k / 10 local y = floor(y0 - L * f * f + 0.5) rect(x0 - k, y - 1, 1, 4, c3(OUT)) if k < 10 then rect(x0 - k, y, 1, 2, c3(WH)) end end end local GX, GB, GH, GP = {}, {}, {}, {} for i = 0, 15 do local h = hash32(i * 0x85EBCA6B + 17) GX[i + 1] = i * 4 + umod(h, 3) GB[i + 1] = 58 + umod(h >> 4, 5) GH[i + 1] = 6 + umod(h >> 8, 4) GP[i + 1] = umod(h >> 12, 628) / 100 end local function grass(t) local a = t * TAU / 90 for i = 1, #GX do local x, top = GX[i], GB[i] - GH[i] + 1 rect(x, top + 1, 1, GH[i] - 1, c3(BLADE)) local s = 0.9 * sin(a + GP[i]) + 0.5 local ix = floor(s) local f = s - ix blend(x + ix, top, BLADE[1], BLADE[2], BLADE[3], 1 - f) blend(x + ix + 1, top, BLADE[1], BLADE[2], BLADE[3], f) end end local LX, LY = CX + 48, CY + 11 local WING, WING2, TIP, BODYB = { 255, 168, 40 }, { 255, 214, 90 }, { 80, 44, 30 }, { 50, 30, 30 } local function butterfly(t) local u = t % 420 local x, y, open if u < 70 then local k = 1 - u / 70 x = LX - 70 + u y = LY - floor(22 * k + 3 * sin(u * TAU / 16) * k + 0.5) open = (u // 3) % 2 == 0 elseif u < 250 then x, y = LX, LY open = ((u - 70) // 24) % 2 == 0 elseif u < 330 then local v = u - 250 x = LX + v y = LY - floor(v * 0.7 + 3 * sin(v * TAU / 16) + 0.5) open = (v // 3) % 2 == 0 else return end if open then rect(x - 2, y - 3, 2, 2, c3(WING)); rect(x + 1, y - 3, 2, 2, c3(WING)) px(x - 1, y - 1, c3(WING2)); px(x + 1, y - 1, c3(WING2)) px(x - 2, y - 3, c3(TIP)); px(x + 2, y - 3, c3(TIP)) else rect(x - 1, y - 4, 1, 2, c3(WING)); rect(x + 1, y - 4, 1, 2, c3(WING)) end rect(x, y - 2, 1, 3, c3(BODYB)) end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local t = frame * STEP_HZ // FPS local b = 0.5 - 0.5 * math.cos(t * TAU / 96) blend_rect(CX + 13, CY - 1, 10, 1, OUT[1], OUT[2], OUT[3], b) blend_rect(CX + 13, CY, 10, 1, WH[1], WH[2], WH[3], b) tail(t) blink(t) grass(t) if cfg.fly ~= false then butterfly(t) end end