info = { type = "image", title = "Purple singer", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "A fuzzy purple monster sings little notes", api = 33, } local tr = ({ sk = { ["Fur colour"] = "Farba srsti", ["Notes"] = "Noty", ["Dance"] = "Tanec" }, cs = { ["Fur colour"] = "Barva srsti", ["Notes"] = "Noty", ["Dance"] = "Tanec" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "body", label = T("Fur colour"), type = "color", default = "#8E3BE8" }, { key = "notes", label = T("Notes"), type = "int", min = 1, max = 6, default = 3 }, { key = "dance", label = T("Dance"), type = "bool", default = true }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sin, cos, sqrt, exp = math.floor, math.sin, math.cos, math.sqrt, math.exp local hash32 = math.hash32 local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local TAU, PI = 6.2831853, 3.1415927 local WALL, CONE1, CONE2 = { 34, 14, 58 }, { 48, 22, 80 }, { 64, 32, 104 } local FLOOR, FLOOR_L = { 88, 44, 112 }, { 130, 74, 150 } local INK, WHITE = { 36, 10, 52 }, { 252, 250, 255 } local PINK = { 255, 150, 206 } local NOTEC = { { 255, 214, 96 }, { 120, 238, 255 }, { 255, 146, 200 }, { 170, 255, 140 }, { 255, 255, 255 } } local LAMPC = { { 255, 90, 120 }, { 255, 210, 80 }, { 90, 240, 160 }, { 100, 170, 255 } } local C, CD, CL, EAR = { 142, 59, 232 }, { 88, 36, 144 }, { 188, 124, 255 }, { 220, 110, 200 } function on_settings() local c = cfg.body or { r = 142, g = 59, b = 232 } C = { c.r, c.g, c.b } CD = { c.r * 62 // 100, c.g * 62 // 100, c.b * 62 // 100 } CL = { c.r + (255 - c.r) * 36 // 100, c.g + (255 - c.g) * 36 // 100, c.b + (255 - c.b) * 36 // 100 } EAR = { c.r + (PINK[1] - c.r) * 7 // 10, c.g + (PINK[2] - c.g) * 7 // 10, c.b + (PINK[3] - c.b) * 7 // 10 } end local function c3(c) return c[1], c[2], c[3] end local function ell(cx, cy, rx, ry, r, g, b) for y = floor(cy - ry + 0.5), floor(cy + ry - 0.5) do local d = (y + 0.5 - cy) / ry if d > -1 and d < 1 then local hw = rx * sqrt(1 - d * d) local x1, x2 = floor(cx - hw + 0.5), floor(cx + hw + 0.5) if x2 > x1 then rect(x1, y, x2 - x1, 1, r, g, b) end end end end local BG = nil local function build_bg() rect(0, 0, W, H, c3(WALL)) for y = 0, 56 do local h1, h2 = 12 + y * 0.34, 8 + y * 0.22 rect(floor(32 - h1), y, floor(2 * h1), 1, c3(CONE1)) rect(floor(32 - h2), y, floor(2 * h2), 1, c3(CONE2)) end rect(0, 57, W, 7, c3(FLOOR)) rect(0, 57, W, 1, c3(FLOOR_L)) for x = 6, W, 14 do rect(x, 58, 1, 6, c3(WALL)) end rect(0, 0, W, 3, c3(INK)) rect(14, 58, 36, 2, 70, 32, 92) BG = gfx.snapshot(0, 0, W, H) end local B = 18 local function hop(f, dance) if not dance then return 0 end return -3.2 * sin(PI * ((f % B) / B)) end local function ear(base_x, base_y, tip_x, tip_y, hw) local n = base_y - tip_y for y = tip_y, base_y do local t = (y - tip_y) / n local x = tip_x + (base_x - tip_x) * t local w = 1 + hw * t local x1, x2 = floor(x - w + 0.5), floor(x + w + 0.5) rect(x1, y, x2 - x1, 1, c3(C)) if t > 0.25 then local k = floor(w * 0.5 + 0.5) if x2 - x1 - 2 * k > 0 then rect(x1 + k, y, x2 - x1 - 2 * k, 1, c3(EAR)) end end end end local function note(x, y, ci, a) local c = NOTEC[ci] local r, g, b = c[1], c[2], c[3] if a >= 1 then rect(x, y + 5, 3, 2, r, g, b) rect(x + 2, y, 1, 6, r, g, b) px(x + 3, y + 1, r, g, b); px(x + 4, y + 2, r, g, b) else blend_rect(x, y + 5, 3, 2, r, g, b, a) blend_rect(x + 2, y, 1, 6, r, g, b, a) blend_rect(x + 3, y + 1, 1, 1, r, g, b, a); blend_rect(x + 4, y + 2, 1, 1, r, g, b, a) end end local LIFE = 84 function render() if not BG then build_bg() end local f = frame * STEP_HZ // FPS gfx.blit_rgb(BG, 0, 0, W, H) local dance = cfg.dance ~= false local nn = cfg.notes or 3 local iv = 72 // nn local lk = (f // 9) % 4 for i = 0, 4 do local c = LAMPC[(i + lk) % 4 + 1] rect(6 + i * 13, 1, 3, 2, c3(c)) end local u = (f % B) / B local dy = hop(f, dance) local sq = dance and 0.07 * cos(TAU * u) or 0.02 * sin(f * 0.07) local cx, cy = 32, 41 + dy local rx, ry = 16 * (1 + sq * 0.8), 14 * (1 - sq) local bot = cy + ry local dl = hop(f - 3, dance) - dy local p = f % 150 local fl = 0 if p < 36 then fl = 4 * exp(-p / 11) * sin(p * 0.85) end local idle = sin(f * 0.05) ear(22, floor(cy - ry + 4), floor(17 + fl + idle), floor(cy - ry - 18 + dl), 4.5) ear(42, floor(cy - ry + 4), floor(47 - fl * 0.6 - idle), floor(cy - ry - 18 + dl), 4.5) ell(23, 56, 4.5, 2.2, c3(CD)); ell(41, 56, 4.5, 2.2, c3(CD)) local arm = dance and floor(2.5 * sin(PI * u) + 0.5) or 0 ell(14, cy + 5 - arm, 2.6, 4, c3(CD)); ell(50, cy + 5 - arm, 2.6, 4, c3(CD)) ell(cx, cy, rx, ry, c3(CD)) ell(cx - 1, cy - 1, rx - 1, ry - 1, c3(C)) ell(cx, cy + 6, 8.5, 6, c3(CL)) local look = floor(1.4 * sin(f * 0.04) + 0.5) local blink = (f + 60) % 130 < 4 for k = 0, 1 do local ex, ey = 25 + 14 * k, floor(cy - 6) if blink then rect(ex - 3, ey, 7, 1, c3(INK)) else ell(ex + 0.5, ey, 3.8, 3.8, c3(WHITE)) rect(ex - 1 + look, ey - 1, 2, 3, c3(INK)) px(ex - 1 + look, ey - 1, c3(WHITE)) end end blend_rect(18, floor(cy + 1), 4, 2, PINK[1], PINK[2], PINK[3], 0.45) blend_rect(42, floor(cy + 1), 4, 2, PINK[1], PINK[2], PINK[3], 0.45) local m = f // iv local tau = f - m * iv local rest = m % 8 == 7 local open = rest and 0.15 or (0.3 + 0.7 * exp(-tau / 7)) local pitch = 0.6 + 0.4 * ((hash32(m * 0x9E3779B1) & 0x7FFF) % 100) / 100 local mry = 1.2 + 2.6 * open * pitch local my = cy + 7 - 0.5 * (mry - 1.2) ell(32, my, 2.7, mry, c3(INK)) if mry > 2.6 then ell(32, my + mry * 0.35, 1.7, mry * 0.45, PINK[1] * 8 // 10, 60, 120) end for q = m, m - LIFE // iv, -1 do if q % 8 ~= 7 then local t = f - q * iv if t >= 0 and t < LIFE then local dir = (q % 2 == 0) and 1 or -1 local x = 32 + dir * (4 + 17 * (1 - exp(-t / 14)) + 0.14 * t) + 2 * sin(t * 0.12 + q) local y = 42 - 0.44 * t local a = t > LIFE - 24 and (LIFE - t) / 24 or 1 note(floor(x), floor(y), (q % 5) + 1, a) end end end end