info = { type = "image", title = "Shiba and cat", category = "animals", author = "BRRRO", version = "1.0", license = "MIT", desc = "Shiba and cat cuddle by a window with Fuji", api = 33, } local tr = ({ sk = { ["Time of day"] = "Denná doba", ["day"] = "deň", ["dusk"] = "súmrak", ["night"] = "noc", ["Cat"] = "Mačka", ["grey"] = "sivá", ["white"] = "biela", ["black"] = "čierna", ["Petals"] = "Lupene" }, cs = { ["Time of day"] = "Denní doba", ["day"] = "den", ["dusk"] = "soumrak", ["night"] = "noc", ["Cat"] = "Kočka", ["grey"] = "šedá", ["white"] = "bílá", ["black"] = "černá", ["Petals"] = "Okvětní lístky" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "time", label = T("Time of day"), type = "int", default = 1, opts = { T("day"), T("dusk"), T("night") } }, { key = "cat", label = T("Cat"), type = "int", default = 0, opts = { T("grey"), T("white"), T("black") } }, { key = "petals", label = T("Petals"), type = "int", min = 0, max = 16, default = 8 }, } local rect, px, blend, brect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local floor, sin, sqrt = math.floor, math.sin, math.sqrt local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local DAY = { wall = { 240, 220, 172 }, trim = { 126, 82, 52 }, triml = { 160, 110, 70 }, floor = { 160, 176, 84 }, floord = { 126, 142, 64 }, floorl = { 180, 194, 104 }, sky = { 150, 208, 242 }, fuji = { 88, 112, 172 }, fujid = { 66, 90, 148 }, cap = { 248, 250, 255 }, hill = { 70, 132, 110 }, cloud = { 252, 252, 255 }, star = false, } local DUSK = { wall = { 232, 190, 160 }, trim = { 118, 66, 56 }, triml = { 154, 98, 76 }, floor = { 150, 142, 92 }, floord = { 118, 108, 70 }, floorl = { 172, 164, 110 }, sky = { 176, 156, 226 }, fuji = { 90, 74, 156 }, fujid = { 68, 54, 128 }, cap = { 255, 232, 244 }, hill = { 84, 62, 118 }, cloud = { 236, 190, 214 }, star = false, } local NIGHT = { wall = { 96, 84, 130 }, trim = { 60, 38, 44 }, triml = { 88, 58, 60 }, floor = { 82, 104, 92 }, floord = { 62, 82, 72 }, floorl = { 98, 122, 108 }, sky = { 26, 36, 90 }, fuji = { 58, 78, 138 }, fujid = { 40, 56, 112 }, cap = { 196, 212, 244 }, hill = { 30, 60, 70 }, cloud = { 52, 66, 122 }, star = true, } local TIMES = { DAY, DUSK, NIGHT } local CATS = { { c = { 156, 158, 176 }, d = { 116, 118, 142 }, l = { 224, 226, 238 } }, { c = { 244, 242, 248 }, d = { 196, 194, 214 }, l = { 255, 255, 255 } }, { c = { 62, 60, 78 }, d = { 38, 36, 54 }, l = { 118, 114, 140 } }, } local P, CT = DUSK, CATS[1] local ORANGE, ORANGE_D = { 240, 150, 60 }, { 206, 110, 40 } local CREAM = { 252, 236, 206 } local EYE, NOSE = { 70, 40, 36 }, { 56, 34, 34 } local PINKC = { 255, 176, 206 } local EAR_IN = { 255, 190, 150 } local PETAL = { 255, 158, 198 } local GREEN = { 120, 204, 110 } local function ell(cx, cy, rx, ry, c, cd, rim) local r, g, b = c[1], c[2], c[3] for y = floor(cy - ry), floor(cy + ry) do local m = y + 0.5 - cy local dy = m / ry local q = 1 - dy * dy if q > 0 then local hw = rx * sqrt(q) local xa, xb = floor(cx - hw + 0.5), floor(cx + hw + 0.5) local a = ry - (m < 0 and -m or m) + 0.5 if xb > xa and a > 0 then local low = cd and dy > 0.72 if a < 1 then local col = low and cd or c brect(xa, y, xb - xa, 1, col[1], col[2], col[3], a) elseif low then rect(xa, y, xb - xa, 1, cd[1], cd[2], cd[3]) elseif cd and xb - xa > rim + 2 then rect(xa, y, xb - xa - rim, 1, r, g, b) rect(xb - rim, y, rim, 1, cd[1], cd[2], cd[3]) else rect(xa, y, xb - xa, 1, r, g, b) end end end end end local function tri(tx, ty, h, lw, rw, c) for i = 0, h - 1 do local f = (i + 1) / h local xa = floor(tx - lw * f + 0.5) rect(xa, ty + i, floor(tx + rw * f + 0.5) - xa, 1, c[1], c[2], c[3]) end end local BG = nil local function build_bg() local S = P rect(0, 0, W, 42, S.wall[1], S.wall[2], S.wall[3]) rect(0, 42, W, 2, S.trim[1], S.trim[2], S.trim[3]) rect(0, 44, W, 20, S.floor[1], S.floor[2], S.floor[3]) rect(0, 44, W, 1, S.floorl[1], S.floorl[2], S.floorl[3]) rect(20, 45, 1, 19, S.floord[1], S.floord[2], S.floord[3]) rect(44, 45, 1, 19, S.floord[1], S.floord[2], S.floord[3]) rect(9, 3, 46, 24, S.trim[1], S.trim[2], S.trim[3]) rect(11, 5, 42, 20, S.sky[1], S.sky[2], S.sky[3]) if S.star then local st = { { 15, 8 }, { 22, 12 }, { 41, 7 }, { 28, 6 }, { 49, 14 }, { 18, 18 } } for i = 1, #st do px(st[i][1], st[i][2], 224, 232, 255) end ell(46.5, 9.5, 2.8, 2.8, { 250, 246, 210 }) else rect(14, 10, 9, 1, S.cloud[1], S.cloud[2], S.cloud[3]) rect(16, 11, 12, 1, S.cloud[1], S.cloud[2], S.cloud[3]) rect(40, 15, 9, 1, S.cloud[1], S.cloud[2], S.cloud[3]) end for y = 8, 24 do local hw = (y - 8 + 0.7) * 1.35 local xa, xb = floor(34 - hw + 0.5), floor(34 + hw + 0.5) if xa < 11 then xa = 11 end if xb > 53 then xb = 53 end rect(xa, y, xb - xa, 1, S.fuji[1], S.fuji[2], S.fuji[3]) local xm = xa + (xb - xa) * 65 // 100 rect(xm, y, xb - xm, 1, S.fujid[1], S.fujid[2], S.fujid[3]) if y <= 13 then rect(xa, y, xm - xa, 1, S.cap[1], S.cap[2], S.cap[3]) end if y == 14 or y == 15 then for x = xa, xm - 1 do if (x + y) % 4 < 2 then px(x, y, S.cap[1], S.cap[2], S.cap[3]) end end end end rect(11, 22, 42, 3, S.hill[1], S.hill[2], S.hill[3]) rect(8, 25, 48, 3, S.triml[1], S.triml[2], S.triml[3]) ell(34, 61, 28, 2.5, S.floord, nil, 0) ell(10, 47, 5, 6.5, ORANGE_D, nil, 0) ell(25, 49.5, 14, 12, ORANGE, ORANGE_D, 2) ell(47.5, 52.3, 11, 9.7, CT.c, CT.d, 2) BG = gfx.snapshot(0, 0, W, H) end local NP = 8 function on_settings() P = TIMES[(cfg.time or 1) + 1] or DUSK CT = CATS[(cfg.cat or 0) + 1] or CATS[1] NP = cfg.petals or 8 BG = nil end local PX, PY, PV, PPH = {}, {}, {}, {} for i = 1, 16 do local h = hash32(i * 0x9E3779B1) PX[i] = umod(h, 60) PY[i] = umod(h >> 8, 30) PV[i] = 4.5 + umod(h >> 14, 30) / 10.0 PPH[i] = umod(h >> 20, 628) / 100.0 end local function draw_petals(ts) gfx.clip(11, 5, 42, 20) for i = 1, NP do local y = (PY[i] + PV[i] * ts) % 30 - 5 local x = (PX[i] + 3.2 * ts + 3 * sin(ts * 1.3 + PPH[i])) % 56 - 6 + 9 local ix, iy = floor(x), floor(y) local fx, fy = x - ix, y - iy for k = 0, 1 do local a = k == 0 and 0.95 or 0.7 blend(ix + k, iy, PETAL[1], PETAL[2], PETAL[3], (1 - fx) * (1 - fy) * a) blend(ix + k + 1, iy, PETAL[1], PETAL[2], PETAL[3], fx * (1 - fy) * a) blend(ix + k, iy + 1, PETAL[1], PETAL[2], PETAL[3], (1 - fx) * fy * a) blend(ix + k + 1, iy + 1, PETAL[1], PETAL[2], PETAL[3], fx * fy * a) end end gfx.clip() end local function draw_shiba(t, ts, b) ell(10.8 + 0.7 * sin(ts * 3.1), 45.6, 2.4, 3, CREAM, nil, 0) ell(24, 54 - 0.3 * b, 8.5 + 0.5 * b, 7.5 + 0.3 * b, CREAM, nil, 0) ell(19.5, 60.3, 3.6, 2.2, CREAM, nil, 0) ell(29, 60.3, 3.6, 2.2, CREAM, nil, 0) local o = ORANGE local hc = 32.2 - 0.7 * b local tw = (t + 70) % 190 < 5 and 1 or 0 tri(15.5, floor(hc - 9.5) - tw, 7, 2.5, 5.5, o) tri(31.5, floor(hc - 9.5), 7, 5.5, 2.5, o) tri(16.5, floor(hc - 8.5) - tw + 2, 4, 1, 2.6, EAR_IN) tri(30.5, floor(hc - 8.5) + 2, 4, 2.6, 1, EAR_IN) ell(23.5, hc, 11, 9, o, ORANGE_D, 2) ell(23.5, hc + 4.2, 8, 4.8, CREAM, nil, 0) ell(16.8, hc + 3.5, 3.6, 3.4, CREAM, nil, 0) ell(30.2, hc + 3.5, 3.6, 3.4, CREAM, nil, 0) local ey = floor(hc + 0.2) px(19, floor(hc - 3), CREAM[1], CREAM[2], CREAM[3]); px(28, floor(hc - 3), CREAM[1], CREAM[2], CREAM[3]) for k = 0, 1 do local ex = 19 + k * 9 px(ex, ey, EYE[1], EYE[2], EYE[3]) px(ex - 1, ey + 1, EYE[1], EYE[2], EYE[3]); px(ex + 1, ey + 1, EYE[1], EYE[2], EYE[3]) end brect(15, ey + 2, 4, 2, 255, 140, 150, 0.55) brect(29, ey + 2, 4, 2, 255, 140, 150, 0.55) rect(23, ey + 3, 2, 1, NOSE[1], NOSE[2], NOSE[3]) px(22, ey + 5, EYE[1], EYE[2], EYE[3]); px(23, ey + 6, EYE[1], EYE[2], EYE[3]) px(24, ey + 6, EYE[1], EYE[2], EYE[3]); px(25, ey + 5, EYE[1], EYE[2], EYE[3]) end local function draw_cat(t, ts, b) local c, d, l = CT.c, CT.d, CT.l for i = 0, 12 do local s = i / 12 local x = 56.5 + 4.2 * sin(s * 1.5) + 2.4 * s * s * sin(ts * 2.6) local y = 58 - 12 * s local col = i >= 10 and d or c rect(floor(x), floor(y), 2, 2, col[1], col[2], col[3]) end ell(46, 56.8 - 0.3 * b, 6 + 0.4 * b, 5 + 0.3 * b, l, nil, 0) ell(42.5, 61, 3.2, 1.8, l, nil, 0) ell(52, 61, 3.2, 1.8, l, nil, 0) local hc = 41.3 - 0.6 * b local tw = (t + 20) % 230 < 5 and 1 or 0 tri(36.5, floor(hc - 11), 8, 1.5, 4.5, c) tri(50.5, floor(hc - 11) - tw, 8, 4.5, 1.5, c) tri(37.2, floor(hc - 9), 5, 0.6, 2.4, PINKC) tri(49.8, floor(hc - 9) - tw + 1, 5, 2.4, 0.6, PINKC) ell(43.5, hc, 9, 7.5, c, d, 2) rect(41, floor(hc - 6), 1, 3, d[1], d[2], d[3]) rect(43, floor(hc - 7), 1, 3, d[1], d[2], d[3]) rect(45, floor(hc - 6), 1, 3, d[1], d[2], d[3]) ell(43.5, hc + 3.3, 4.2, 2.8, l, nil, 0) local ey = floor(hc) if (ts + 3) % 8 < 1.2 then for k = 0, 1 do local ex = 39 + k * 7 rect(ex, ey, 2, 2, GREEN[1], GREEN[2], GREEN[3]) px(ex + 1, ey, 24, 24, 36); px(ex + 1, ey + 1, 24, 24, 36) end else for k = 0, 1 do local ex = 40 + k * 7 px(ex - 1, ey, EYE[1], EYE[2], EYE[3]); px(ex + 1, ey, EYE[1], EYE[2], EYE[3]) px(ex, ey + 1, EYE[1], EYE[2], EYE[3]) end end brect(37, ey + 2, 3, 2, 255, 150, 170, 0.5) brect(48, ey + 2, 3, 2, 255, 150, 170, 0.5) rect(43, ey + 3, 2, 1, PINKC[1], PINKC[2], PINKC[3]) 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 ts = t / gfx.FPS if NP > 0 then draw_petals(ts) end draw_shiba(t, ts, sin(ts * 1.95)) draw_cat(t, ts, sin(ts * 2.2 + 1.2)) end