info = { type = "image", title = "Glass lick", category = "animals", author = "BRRRO", version = "1.0", license = "MIT", desc = "A dog peeks in, sniffs and licks the screen", api = 33, } local tr = ({ sk = { ["Coat"] = "Srsť", ["Tan"] = "Béžová", ["Brown"] = "Hnedá", ["Grey"] = "Sivá", ["Licks"] = "Olízania" }, cs = { ["Coat"] = "Srst", ["Tan"] = "Béžová", ["Brown"] = "Hnědá", ["Grey"] = "Šedá", ["Licks"] = "Olíznutí" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "coat", label = T("Coat"), type = "int", default = "tan", opts = { keys = { "tan", "brown", "grey" }, T("Tan"), T("Brown"), T("Grey") } }, { key = "licks", label = T("Licks"), type = "int", min = 1, max = 3, default = 2 }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local blit_rgb, blit_indexed, snapshot = gfx.blit_rgb, gfx.blit_indexed, gfx.snapshot local floor, ceil, sin, min, max = math.floor, math.ceil, math.sin, math.min, math.max local hash32, umod = math.hash32, math.umod local char, unpack, concat = string.char, table.unpack, table.concat local W, H = gfx.W, gfx.H local CYC = 450 local COATS = { tan = { { 232, 150, 52 }, { 192, 110, 36 }, { 250, 230, 198 }, { 222, 196, 160 }, { 150, 84, 36 }, { 112, 62, 28 }, { 250, 190, 100 } }, brown = { { 150, 92, 56 }, { 112, 66, 38 }, { 236, 208, 170 }, { 206, 176, 136 }, { 78, 46, 30 }, { 56, 32, 22 }, { 184, 126, 84 } }, grey = { { 150, 158, 172 }, { 112, 120, 138 }, { 240, 242, 246 }, { 206, 210, 220 }, { 76, 80, 96 }, { 54, 58, 72 }, { 192, 198, 210 } }, } local function mkpal(c) local P = { 0, 0, 0 } for _, v in ipairs({ c[1], c[2], c[3], c[4], c[5], c[6], c[7], { 26, 22, 28 }, { 130, 130, 144 }, { 18, 14, 20 }, { 250, 250, 250 }, { 120, 30, 44 }, { 236, 92, 120 }, { 196, 60, 92 } }) do P[#P + 1], P[#P + 2], P[#P + 3] = v[1], v[2], v[3] end return P end local function build_head(open) local g = {} for i = 1, 1024 do g[i] = 0 end local function ell(cx, cy, rx, ry, v, vs) for y = max(0, floor(cy - ry)), min(31, ceil(cy + ry)) do for x = max(0, floor(cx - rx)), min(31, ceil(cx + rx)) do local u, w = (x + 0.5 - cx) / rx, (y + 0.5 - cy) / ry local r2 = u * u + w * w if r2 <= 1 then g[y * 32 + x + 1] = (vs and r2 > 0.62 and u * 0.4 + w * 0.9 > 0.3) and vs or v end end end end local function dot(x, y, v) g[y * 32 + x + 1] = v end ell(5.5, 13, 4.7, 9.5, 5, 6); ell(26.5, 13, 4.7, 9.5, 5, 6) ell(16, 16.5, 12.5, 11.5, 1, 2) ell(10, 8.5, 2.6, 1.5, 7); ell(22, 8.5, 2.6, 1.5, 7) ell(16, 22.5, 8.5, 6.5, 3, 4) ell(10, 12.5, 2, 2.3, 10); ell(22, 12.5, 2, 2.3, 10) dot(10, 11, 11); dot(22, 11, 11) ell(16, 18.3, 4, 2.8, 8); dot(14, 17, 9); dot(15, 17, 9) for y = 21, 22 do dot(15, y, 12); dot(16, y, 12) end if open then ell(16, 25.5, 5.8, 3.8, 12) ell(16, 27, 3.6, 2.2, 13) dot(15, 25, 14); dot(16, 25, 14); dot(15, 26, 14); dot(16, 26, 14) else for y = 23, 24 do dot(15, y, 12); dot(16, y, 12) end for x = 11, 14 do dot(x, 24, 12) end for x = 17, 20 do dot(x, 24, 12) end dot(10, 23, 12); dot(21, 23, 12) end local rows = {} for y = 0, 31 do rows[y + 1] = char(unpack(g, y * 32 + 1, y * 32 + 32)) end return concat(rows) end local BG, PAL = nil, nil local HEAD, HEAD_OPEN = nil, nil local function bake() for y = 0, 43 do local t = y / 43 rect(0, y, W, 1, floor(112 + 84 * t), floor(184 + 44 * t), floor(242 + 8 * t)) end for _, c in ipairs({ { 8, 9, 14 }, { 40, 17, 18 }, { 24, 24, 12 } }) do blend_rect(c[1], c[2], c[3], 2, 255, 255, 255, 0.85) blend_rect(c[1] + 2, c[2] - 1, c[3] - 5, 4, 255, 255, 255, 0.85) end for x = 0, 63, 4 do rect(x, 33 + floor(2 * sin(x * 0.25) + 0.5), 4, 16, 70, 150, 90) end rect(0, 36, W, 2, 232, 228, 218); rect(0, 42, W, 2, 232, 228, 218) for x = 2, 61, 8 do rect(x, 31, 4, 17, 246, 244, 236); rect(x + 3, 31, 1, 17, 214, 212, 204) rect(x + 1, 30, 2, 1, 246, 244, 236) end for y = 46, H - 1 do local t = (y - 46) / 17 rect(0, y, W, 1, floor(124 - 44 * t), floor(192 - 46 * t), floor(88 - 26 * t)) end for i = 1, 40 do local h = hash32(i * 0x9E3779B1) local x, y = umod(h, W), 48 + umod(h >> 8, 16) rect(x, y, 1, 2, 58, 124, 50) end BG = snapshot(0, 0, W, H) end function on_settings() BG, PAL = nil, mkpal(COATS[cfg.coat] or COATS.tan) end local KF = { { 0, 28, 92 }, { 30, 28, 92 }, { 70, 28, 57 }, { 90, 28, 57 }, { 128, 46, 42 }, { 152, 74, 36 }, { 300, 74, 36 }, { 350, 52, 112 }, { CYC, 52, 112 } } local function pose(c) for i = 1, #KF - 1 do local a, b = KF[i], KF[i + 1] if c <= b[1] then local u = (c - a[1]) / (b[1] - a[1]) u = u * u * (3 - 2 * u) return a[2] + (b[2] - a[2]) * u, a[3] + (b[3] - a[3]) * u end end return 28, 92 end local FADE = 170 local XA, XB, MX, MY = 14, 50, 32, 57 local T_OUT, T_SW, T_BACK, T_SHUT = 190, 198, 258, 268 local TONGUE, SHINE, WET = { 236, 92, 120 }, { 252, 150, 170 }, { 235, 245, 255 } local function ease(f) return f * f * (3 - 2 * f) end function render() if not BG then bake() else blit_rgb(BG, 0, 0, W, H) end if not HEAD then HEAD = build_head(false) elseif not HEAD_OPEN then HEAD_OPEN = build_head(true) end PAL = PAL or mkpal(COATS[cfg.coat] or COATS.tan) local c = (frame + 30) % CYC local sz, cy = pose(c) local cx = 32 + 5 * sin((c - 60) * 0.1) * max(0, min(1, (140 - c) / 40)) local sniff = (c >= 152 and c < 188) or (c >= 270 and c < 300) if sniff or (c >= T_OUT and c < T_SHUT) then cy = cy + (c // 3) % 2 end sz, cy, cx = floor(sz + 0.5), floor(cy + 0.5), floor(cx + 0.5) local k = sz / 32 if HEAD_OPEN and cy - sz // 2 < H then blit_indexed((c >= 188 and c < T_SHUT) and HEAD_OPEN or HEAD, PAL, cx - sz // 2, cy - sz // 2, sz, sz, 32, 32, true) if c % 90 < 3 and c > 60 then local ew, eh = ceil(4 * k), ceil(4.6 * k) local fur = PAL for _, ex in ipairs({ 10, 22 }) do local x, y = floor(cx + (ex - 16) * k - ew / 2 + 0.5), floor(cy + (12.5 - 16) * k - eh / 2 + 0.5) rect(x, y, ew, eh, fur[4], fur[5], fur[6]) rect(x, y + eh // 2, ew, 1, 18, 14, 20) end end end local n = cfg.licks or 2 local slot = (T_BACK - T_SW) / n local tx, ty for i = 0, n - 1 do local yb = 50 - 6 * i local t0 = T_SW + i * slot local ltr = i % 2 == 0 if c >= t0 then local f = min(1, (c - t0) / slot) local xt = ltr and XA + (XB - XA) * ease(f) or XB - (XB - XA) * ease(f) xt = floor(xt + 0.5) local a = f < 1 and 0.5 or 0.5 * (1 - (c - t0 - slot) / FADE) if a > 0.01 then if ltr then blend_rect(XA, yb, xt - XA + 1, 6, WET[1], WET[2], WET[3], a) else blend_rect(xt, yb, XB - xt + 1, 6, WET[1], WET[2], WET[3], a) end if f >= 1 then local len = min(12, (c - t0 - slot - 10) * 0.1) if len >= 1 then local xd = XA + 8 + 9 * i blend_rect(xd, yb + 6, 1, floor(len), WET[1], WET[2], WET[3], a * 0.8) blend_rect(xd, yb + 6 + floor(len), 1, 1, WET[1], WET[2], WET[3], a) end end end if f < 1 then tx, ty = xt, yb end end end if c >= T_OUT and c < T_BACK + 8 then local yb0 = 50 if c < T_SW then local s = ease((c - T_OUT) / (T_SW - T_OUT)) tx, ty = floor(MX + (XA - MX) * s + 0.5), floor(MY - 6 + (yb0 - MY + 6) * s + 0.5) elseif c >= T_BACK then local s = ease(min(1, (c - T_BACK) / 8)) local xe = (n % 2 == 1) and XB or XA local ye = 50 - 6 * (n - 1) tx, ty = floor(xe + (MX - xe) * s + 0.5), floor(ye + (MY - 6 - ye) * s + 0.5) end if tx then rect(tx - 5, ty - 1, 11, 8, TONGUE[1], TONGUE[2], TONGUE[3]) rect(tx - 6, ty, 13, 6, TONGUE[1], TONGUE[2], TONGUE[3]) rect(tx - 3, ty + 1, 7, 1, SHINE[1], SHINE[2], SHINE[3]) end end if sniff then local p = (c - 152) % 12 if p < 10 then local a = 0.14 * sin(3.1416 * p / 10) local nx, ny = cx, floor(cy + 2.3 * k + 0.5) blend_rect(nx - 8, ny - 1, 16, 3, 255, 255, 255, a) blend_rect(nx - 5, ny - 3, 10, 7, 255, 255, 255, a) end end end