info = { type = "image", title = "Teddy wave", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "A plush teddy waves and sends hearts", api = 33, } local tr = ({ sk = { ["Fur colour"] = "Farba srsti", ["Waving"] = "Mávanie", ["still"] = "bez pohybu", ["gentle"] = "jemne", ["cheerful"] = "veselo", ["Hearts and sparkles"] = "Srdiečka a iskričky" }, cs = { ["Fur colour"] = "Barva srsti", ["Waving"] = "Mávání", ["still"] = "beze pohybu", ["gentle"] = "jemně", ["cheerful"] = "vesele", ["Hearts and sparkles"] = "Srdíčka a jiskřičky" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "fur", label = T("Fur colour"), type = "color", default = "#B97A56" }, { key = "wave", label = T("Waving"), type = "int", default = 1, opts = { T("still"), T("gentle"), T("cheerful") } }, { key = "hearts", label = T("Hearts and sparkles"), type = "bool", default = true }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sin, cos, sqrt = math.floor, math.sin, math.cos, math.sqrt local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local TAU = 6.28318 local function c3(c) return c[1], c[2], c[3] end local function lerp(a, b, t) return floor(a + (b - a) * t + 0.5) end local FUR, FURL, OUTC = { 185, 122, 86 }, { 227, 184, 148 }, { 70, 46, 33 } local PINK, NOSE, EYE = { 240, 150, 164 }, { 60, 36, 36 }, { 56, 34, 28 } local PAL = { 0, 0, 0, 70, 46, 33, 185, 122, 86 } local CX, CY = 32, 26 local SHX, SHY = 44, 41 local function discs(n, idx) local rows = {} local r = n / 2 for y = 0, n - 1 do local row = {} for x = 0, n - 1 do local dx, dy = x + 0.5 - r, y + 0.5 - r row[x + 1] = (dx * dx + dy * dy <= r * r) and idx or 0 end rows[y + 1] = string.char(table.unpack(row, 1, n)) end return table.concat(rows) end local O7, F5, O9, F7 = discs(7, 1), discs(5, 2), discs(9, 1), discs(7, 2) local HROWS = { ".#.#.", "#####", "#####", ".###.", "..#.." } local HEART do local t = {} for y = 1, 5 do for x = 1, 5 do t[#t + 1] = HROWS[y]:sub(x, x) == "#" and "\255" or "\0" end end HEART = table.concat(t) end local function disc(cx, cy, r, c) for y = floor(cy - r), floor(cy + r) do local dy = y + 0.5 - cy local k = r * r - dy * dy if k > 0 then local w = sqrt(k) local x0 = floor(cx - w + 0.5) rect(x0, y, floor(cx + w + 0.5) - x0, 1, c3(c)) end end end local function ell(cx, cy, rx, ry, c) for y = floor(cy - ry), floor(cy + ry) do local dy = (y + 0.5 - cy) / ry local k = 1 - dy * dy if k > 0 then local w = rx * sqrt(k) local x0 = floor(cx - w + 0.5) rect(x0, y, floor(cx + w + 0.5) - x0, 1, c3(c)) end end end local BG = nil local FLAG = { { 255, 120, 140 }, { 255, 206, 96 }, { 120, 200, 210 }, { 176, 150, 230 } } local function build_bg() for x = 0, W - 1, 8 do local c = ((x // 8) % 2 == 0) and { 255, 240, 218 } or { 252, 224, 204 } rect(x, 0, 8, 45, c3(c)) end rect(0, 44, W, 3, 255, 250, 244) rect(0, 46, W, 1, 226, 206, 188) rect(0, 47, W, 17, 206, 150, 104) rect(0, 53, W, 1, 184, 126, 88); rect(0, 59, W, 1, 184, 126, 88) for i = 0, 3 do rect(6 + i * 17, 47, 1, 6, 184, 126, 88) end for i = 0, 3 do rect(14 + i * 17, 54, 1, 5, 184, 126, 88) end for i = 0, 3 do rect(2 + i * 17, 60, 1, 4, 184, 126, 88) end rect(0, 47, W, 1, 222, 168, 122) ell(32, 56, 28, 6.4, { 255, 170, 192 }) ell(32, 56, 22, 4.6, { 255, 198, 214 }) for x = 0, W - 1 do local y = 2 + floor(3 * sin(x / (W - 1) * 3.14159) + 0.5) rect(x, y, 1, 1, 150, 120, 110) if x % 9 == 4 then local c = FLAG[(x // 9) % 4 + 1] rect(x - 2, y + 1, 5, 1, c3(c)); rect(x - 1, y + 2, 3, 1, c3(c)); rect(x, y + 3, 1, 1, c3(c)) end end ell(32, 45, 14.2, 11.8, OUTC); ell(32, 45, 13.2, 10.8, FUR) ell(32, 47, 8.2, 7.2, FURL) for _, fx in ipairs({ 22, 42 }) do ell(fx, 54.5, 6.4, 4.6, OUTC); ell(fx, 54.5, 5.4, 3.6, FUR) ell(fx, 55, 3, 2, PINK) end for k = 0, 4 do local x, y = 20.8 - k * 0.8, 41 + k * 2.6 disc(x, y, 3.8, OUTC) end for k = 0, 4 do local x, y = 20.8 - k * 0.8, 41 + k * 2.6 disc(x, y, 2.9, FUR) end ell(28.3, 41, 3.4, 2.4, { 150, 30, 50 }); ell(35.7, 41, 3.4, 2.4, { 150, 30, 50 }) ell(28.3, 41, 2.6, 1.7, { 220, 64, 80 }); ell(35.7, 41, 2.6, 1.7, { 220, 64, 80 }) disc(32, 41, 1.6, { 150, 30, 50 }) BG = gfx.snapshot(0, 0, W, H) end function on_settings() local c = cfg.fur or { r = 185, g = 122, b = 86 } FUR = { c.r, c.g, c.b } FURL = { lerp(c.r, 255, 0.6), lerp(c.g, 226, 0.6), lerp(c.b, 190, 0.6) } OUTC = { c.r * 38 // 100, c.g * 38 // 100, c.b * 38 // 100 } PAL = { 0, 0, 0, OUTC[1], OUTC[2], OUTC[3], c.r, c.g, c.b } BG = nil end local WAVEC = { [1] = 300, [2] = 210 } local WAVEP = { [1] = 30, [2] = 18 } local UP0, UPN, WAVEN, DOWNN = 40, 18, { [1] = 120, [2] = 90 }, 18 local REST, RAISED = 2.9, 0.95 local function ease(x) return x * x * (3 - 2 * x) end local function arm(t, mode) local C = WAVEC[mode] if not C then return REST, 0 end local u = t % C if u < UP0 then return REST, 0 end if u < UP0 + UPN then local e = ease((u - UP0) / UPN) return REST + (RAISED - REST) * e, e end local w = u - UP0 - UPN if w < WAVEN[mode] then return RAISED + 0.4 * sin(w * TAU / WAVEP[mode]), 1 end w = w - WAVEN[mode] if w < DOWNN then local e = ease(w / DOWNN) return RAISED + (REST - RAISED) * e, 1 - e end return REST, 0 end local BNC = 0 local function hp(lx, ly) return CX + lx, CY + ly + BNC end local function paw(ang) local n = 7 local dx, dy = sin(ang), -cos(ang) for k = 0, n do local r = k * 1.7 gfx.blit_indexed(O7, PAL, floor(SHX + dx * r - 3 + 0.5), floor(SHY + dy * r - 3 + 0.5), 7, 7, 7, 7, true) end local tx, ty = SHX + dx * 13.5, SHY + dy * 13.5 gfx.blit_indexed(O9, PAL, floor(tx - 4 + 0.5), floor(ty - 4 + 0.5), 9, 9, 9, 9, true) for k = 0, n do local r = k * 1.7 gfx.blit_indexed(F5, PAL, floor(SHX + dx * r - 2 + 0.5), floor(SHY + dy * r - 2 + 0.5), 5, 5, 5, 5, true) end gfx.blit_indexed(F7, PAL, floor(tx - 3 + 0.5), floor(ty - 3 + 0.5), 7, 7, 7, 7, true) rect(floor(tx + 0.5) - 1, floor(ty + 0.5) - 1, 3, 2, c3(PINK)) end local SPX = { 6, 10, 3, 57, 60, 52, 14 } local SPY = { 14, 31, 40, 17, 31, 8, 7 } local function heart(x, y, a) local ix = floor(x) local f = x - ix local iy = floor(y + 0.5) gfx.blend_mask(HEART, 255, 96, 130, ix, iy, 5, 5, 5, 5, a * (1 - f)) if f > 0.05 then gfx.blend_mask(HEART, 255, 96, 130, ix + 1, iy, 5, 5, 5, 5, a * f) end 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 mode = cfg.wave or 1 local ang, env = arm(t, mode) BNC = -floor(0.7 * env * (sin(t * TAU / 30) ^ 2) + 0.5) local x, y for s = -1, 1, 2 do x, y = hp(s * 10.6, -10.2) disc(x, y, 5.7, OUTC); disc(x, y, 4.6, FUR) x, y = hp(s * 10.4, -9.4); disc(x, y, 2.7, PINK) end x, y = hp(0, 0) disc(x, y, 13.3, OUTC); disc(x, y, 12.3, FUR) x, y = hp(0, 5.4); ell(x, y, 7.6, 5.7, OUTC); ell(x, y, 6.6, 4.7, FURL) local nx, ny = hp(0, 3.4) nx, ny = floor(nx + 0.5), floor(ny + 0.5) rect(nx - 2, ny - 1, 4, 1, c3(NOSE)); rect(nx - 1, ny, 2, 1, c3(NOSE)) px(nx - 1, ny + 2, c3(OUTC)); px(nx, ny + 2, c3(OUTC)); px(nx - 2, ny + 3, c3(OUTC)); px(nx + 1, ny + 3, c3(OUTC)) local blink = (t % 126) < 4 for s = -1, 1, 2 do local ex, ey = hp(s * 7, -2) ex, ey = floor(ex + 0.5), floor(ey + 0.5) if blink then rect(ex - 1, ey + 1, 3, 1, c3(EYE)) else rect(ex - 1, ey - 1, 2, 3, c3(EYE)); px(ex - 1, ey - 1, 255, 255, 255) end local bx, by = hp(s * 10.8, 3.4) blend_rect(floor(bx + 0.5) - 2, floor(by + 0.5) - 1, 4, 2, 255, 130, 146, 0.85) end paw(ang) if cfg.hearts ~= false then local C = WAVEC[mode] if C then local u = t % C - (UP0 + UPN) for j = 0, 2 do local age = u - j * 26 if age >= 0 and age < 76 then local a = (76 - age) / 22 if a > 1 then a = 1 end heart(48 + age * 0.14 + 3 * sin(age * 0.1 + j * 2), 26 - age * 0.30, a) end end end for k = 1, #SPX do local a = sin(t * 0.07 + k * 1.9) if a > 0.2 then a = a * 0.9 blend_rect(SPX[k] - 1, SPY[k], 3, 1, 255, 236, 150, a) blend_rect(SPX[k], SPY[k] - 1, 1, 3, 255, 236, 150, a) end end end end