info = { type = "image", title = "Shiba nap", category = "animals", author = "BRRRO", version = "1.0", license = "MIT", desc = "A shiba naps, dreams of a bone, yawns, turns", api = 33, } local tr = ({ sk = { ["Fur"] = "Srsť", ["Shiba"] = "Šiba", ["Cream"] = "Krémová", ["Dark"] = "Tmavá", ["Dream bubble"] = "Bublina so snom" }, cs = { ["Fur"] = "Srst", ["Shiba"] = "Šiba", ["Cream"] = "Krémová", ["Dark"] = "Tmavá", ["Dream bubble"] = "Bublina se snem" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "fur", label = T("Fur"), type = "int", default = 0, opts = { T("Shiba"), T("Cream"), T("Dark") } }, { key = "dream", label = T("Dream bubble"), type = "bool", default = true }, } local rect, px, blit = gfx.rect, gfx.px, gfx.blit_indexed local floor, ceil, sin, sqrt, max, min = math.floor, math.ceil, math.sin, math.sqrt, math.max, math.min local W, H, FPS = gfx.W, gfx.H, gfx.FPS local TAU = 6.28318 local PERIOD = 660 local GR = {} local function grid(n) for i = 1, n do GR[i] = 0 end; return GR end local function ell(g, w, h, cx, cy, rx, ry, c, dk, lt) for y = max(0, floor(cy - ry)), min(h - 1, ceil(cy + ry)) do local dy = (y + 0.5 - cy) / ry for x = max(0, floor(cx - rx)), min(w - 1, ceil(cx + rx)) do local dx = (x + 0.5 - cx) / rx if dx * dx + dy * dy <= 1 then local k = c if dk and dy > 0.45 then k = dk elseif lt and dx + dy < -0.8 then k = lt end g[y * w + x + 1] = k end end end end local function put(g, w, h, x, y, c) x, y = floor(x), floor(y) if x >= 0 and x < w and y >= 0 and y < h then g[y * w + x + 1] = c end end local function ear(g, w, h, cx, top, eh, base, lean, c) for i = 0, eh - 1 do local wd = 1 + floor(i * (base - 1) / (eh - 1) + 0.5) local sx = cx - wd // 2 + floor((eh - 1 - i) * lean / (eh - 1) + 0.5) for x = sx, sx + wd - 1 do put(g, w, h, x, top + i, c) end end end local function bytes(g, w, h, mir) local t = {} for y = 0, h - 1 do local r = string.char(table.unpack(g, y * w + 1, y * w + w)) t[y + 1] = mir and r:reverse() or r end return table.concat(t) end local FURS = { [0] = { 222, 120, 46, 160, 76, 38, 246, 164, 88 }, [1] = { 232, 196, 140, 184, 146, 96, 250, 224, 178 }, [2] = { 92, 72, 66, 50, 38, 40, 140, 112, 98 }, } local CREAM, DARK, PINK, CREAM_D = { 252, 238, 216 }, { 58, 32, 30 }, { 240, 148, 150 }, { 214, 190, 164 } local PAL = {} local BPAL = { 0, 0, 0, 150, 176, 216, 242, 247, 255, 255, 238, 196, 150, 112, 78 } local WD, HD = 28, 18 local function build_dog(kind, lift) local g = grid(WD * HD) local function E(...) ell(g, WD, HD, ...) end local function P(x, y, c) put(g, WD, HD, x, y, c) end if kind == "front" then E(14, 13, 10, 5, 1, 2, 3) E(9.5, 16.5, 2.5, 1.5, 4, 7) E(18.5, 16.5, 2.5, 1.5, 4, 7) ear(g, WD, HD, 9, 0, 5, 5, 0, 1); ear(g, WD, HD, 19, 0, 5, 5, 0, 1) P(9, 3, 6); P(9, 2, 6); P(19, 3, 6); P(19, 2, 6) E(14, 8, 6.2, 5, 1, 2, 3) E(9, 9.5, 2.5, 2, 4, 7); E(19, 9.5, 2.5, 2, 4, 7) E(14, 10.5, 3.5, 2.5, 4, 7) P(13, 9, 5); P(14, 9, 5); P(14, 11, 5) P(10, 7, 5); P(18, 7, 5); P(10, 5, 3); P(18, 5, 3) else local ry = 5.5 + lift * 0.5 local by = 17.5 - ry E(15, by, 11, ry, 1, 2, 3) E(19, by + 1, 5.6, ry - 0.8, 2) E(19.2, by + 0.8, 4.8, ry - 1.5, 1, 2, 3) E(22.5, by - 3, 5.2, 3.2, 2) E(22.5, by - 3.3, 4.6, 2.7, 1, 2, 3) E(25.5, by - 2, 2.2, 2.2, 4, 7) local hy = (kind == "sleep" or kind == "twitch") and 12.5 or (kind == "yawn" and 7.5 or 8.5) E(8.5, 16.5, 3, 1.5, 4, 7) if hy < 12 then E(9, hy + 4.5, 4.8, 4.8, 1, 2, 3) end E(6.7, hy + 0.2, 6, 5.4, 2) local el, er = 0, 0 if kind == "twitch" then el = -2 end local top = floor(hy - 6) if kind == "yawn" then top = top + 1; er = 1 end ear(g, WD, HD, 4, top, 4, 4, el, 1); ear(g, WD, HD, 9 + er, top, 4, 4, er, 1) P(4 + el // 2, top + 3, 6); P(9 + er, top + 3, 6) E(6.5, hy, 5.4, 4.9, 1, 2, 3) if kind == "yawn" then E(3, hy + 4.5, 3, 1.6, 4, 7) E(2.8, hy + 2.6, 2.6, 2.1, 5) P(3, hy + 3.5, 6); P(4, hy + 3.5, 6) E(3.5, hy + 1, 3, 1.5, 4, 7) else E(3.2, hy + 2.2, 3.4, 2.4, 4, 7) end local ny = kind == "yawn" and hy + 0.5 or hy + 1.5 P(0, ny, 5); P(1, ny, 5) local ey = hy - 1 if kind == "sleep" or kind == "twitch" or kind == "blink" or kind == "yawn" then P(3, ey, 5); P(4, ey, 5); P(7, ey, 5); P(8, ey, 5) else P(4, ey, 5); P(8, ey, 5) end P(4, ey - 2, 3); P(8, ey - 2, 3) end return g end local POSES = {} local function pose(kind, lift) local k = kind .. lift local p = POSES[k] if not p then local g = build_dog(kind, lift) p = { bytes(g, WD, HD), bytes(g, WD, HD, true) } POSES[k] = p end return p end local BW, BH = 24, 18 local BUBBLES = {} local BONE = { ".OOO.....OOO.", "OXXXOOOOOXXXO", "OXXXXXXXXXXXO", "OXXXOOOOOXXXO", ".OOO.....OOO." } local function bubble(stage, bob) local k = stage * 2 + bob local s = BUBBLES[k] if not s then local g = grid(BW * BH) local rx, ry = ({ 4.5, 7.5, 11 })[stage], ({ 3.5, 5.5, 8 })[stage] ell(g, BW, BH, 12, 9, rx, ry, 1) ell(g, BW, BH, 12, 9, rx - 1, ry - 1, 2) if stage == 3 then for r = 1, 5 do local row = BONE[r] for c = 1, 13 do local ch = row:sub(c, c) if ch ~= "." then put(g, BW, BH, 5 + c - 1, 6 + r + bob, ch == "X" and 3 or 4) end end end end s = bytes(g, BW, BH) BUBBLES[k] = s end return s end local BG local BRICK = { { 184, 116, 76 }, { 168, 102, 66 }, { 196, 130, 88 } } local BRICK_L = { { 206, 140, 98 }, { 190, 124, 86 }, { 218, 154, 110 } } local MORT = { 128, 76, 54 } local function disc(cx, cy, rx, ry, r, g, b) for y = floor(cy - ry), ceil(cy + ry) - 1 do local dy = (y + 0.5 - cy) / ry local hw = rx * sqrt(max(0, 1 - dy * dy)) local x0 = floor(cx - hw + 0.5) rect(x0, y, floor(cx + hw + 0.5) - x0, 1, r, g, b) end end local function build_bg() rect(0, 0, W, 44, MORT[1], MORT[2], MORT[3]) for r = 0, 10 do local y, off = r * 4, (r % 2) * 4 for bx = -1, 8 do local x = off + bx * 8 local k = math.hash32(r * 31 + bx * 7 + 5) & 3 if k == 3 then k = 0 end local c, l = BRICK[k + 1], BRICK_L[k + 1] rect(x, y, 7, 3, c[1], c[2], c[3]) rect(x, y, 7, 1, l[1], l[2], l[3]) end end rect(0, 44, W, 1, 214, 160, 110) rect(0, 45, W, 3, 150, 100, 64) rect(0, 48, W, 16, 112, 70, 44) for i, y in ipairs({ 52, 57, 62 }) do rect(0, y, W, 1, 84, 50, 34) local off = (i * 19) % 40 rect(off, y - 4, 1, 4, 84, 50, 34) rect((off + 33) % 64, y - 4, 1, 4, 84, 50, 34) end disc(32, 59.5, 21, 4, 70, 42, 30) disc(32, 55, 18, 6.5, 116, 22, 44) disc(32, 54, 17.5, 5.5, 176, 36, 64) disc(32, 52.5, 12, 3, 202, 54, 82) rect(52, 58, 8, 1, 96, 140, 204) disc(56, 60, 4.5, 2, 70, 104, 168) disc(56, 58.7, 3.2, 0.9, 120, 82, 50) BG = gfx.snapshot(0, 0, W, H) end function on_settings() local f = FURS[cfg.fur or 0] or FURS[0] PAL = { 0, 0, 0, f[1], f[2], f[3], f[4], f[5], f[6], f[7], f[8], f[9], CREAM[1], CREAM[2], CREAM[3], DARK[1], DARK[2], DARK[3], PINK[1], PINK[2], PINK[3], CREAM_D[1], CREAM_D[2], CREAM_D[3] } end local SPARK = { { 0, -10 }, { 8, -7 }, { 11, 1 }, { 8, 8 }, { -8, 8 }, { -11, 1 }, { -8, -7 } } function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local cyc, f = frame // PERIOD, frame % PERIOD local mir = (cyc + (f >= 410 and 1 or 0)) % 2 == 1 local dir = mir and 1 or -1 local kind, lift = "sleep", 1 if f < 270 then if (f >= 150 and f < 156) or (f >= 162 and f < 168) or (f >= 196 and f < 202) then kind = "twitch" else lift = floor(1.5 + 1.2 * sin(f * TAU / 72 - 1.5708) + 0.5) end elseif f < 410 then kind = (f >= 306 and f < 366) and "yawn" or "awake" if (f >= 282 and f < 286) or (f >= 392 and f < 396) then kind = "blink" end elseif f < 440 then kind = "front" elseif f < 470 then kind = "awake" else lift = floor(1.5 + 1.2 * sin((f - 470) * TAU / 72 - 1.5708) + 0.5) end local p = pose(kind, kind == "front" and 0 or (lift < 0 and 0 or (lift > 2 and 2 or lift))) blit(p[mir and 2 or 1], PAL, 18, 38, WD, HD, WD, HD, true) if cfg.dream and f >= 45 and f < 282 then local hx = 32 + dir * 8 local bx = 32 + dir * 10 - 12 if f < 270 then rect(hx - 1, 33, 2, 2, 242, 247, 255) if f >= 55 then rect(hx + dir * 2 - 1, 29, 3, 2, 242, 247, 255); px(hx + dir * 2, 28, 242, 247, 255) end local stage = f >= 82 and 3 or (f >= 74 and 2 or (f >= 66 and 1 or 0)) if stage > 0 then local bob = (f >= 90 and (f // 45) % 2 == 1) and 1 or 0 blit(bubble(stage, stage == 3 and bob or 0), BPAL, bx, 6, BW, BH, BW, BH, true) end else local far = f >= 276 and 3 or 0 for i = 1, #SPARK do local s = SPARK[i] px(bx + 12 + s[1] + (s[1] > 0 and far or (s[1] < 0 and -far or 0)), 15 + s[2] + (s[2] > 0 and far or (s[2] < 0 and -far or 0)), 242, 247, 255) end end end end