info = { type = "image", title = "Lab jelly", category = "animals", author = "BRRRO", version = "1.0", license = "MIT", desc = "Pulsing jellyfish in a lab jar with lights", api = 33, } local ltr = ({ sk = { ["Colour"] = "Farba", ["Bubbles"] = "Bublinky", ["Pulse"] = "Pulz", ["Violet"] = "Fialová", ["Cyan"] = "Azúrová", ["Pink"] = "Ružová" }, cs = { ["Colour"] = "Barva", ["Bubbles"] = "Bublinky", ["Pulse"] = "Puls", ["Violet"] = "Fialová", ["Cyan"] = "Azurová", ["Pink"] = "Růžová" }, })[lang] or {} local function LT(s) return ltr[s] or s end settings = { { key = "tone", label = LT("Colour"), type = "int", default = "violet", opts = { keys = { "violet", "cyan", "pink" }, LT("Violet"), LT("Cyan"), LT("Pink") } }, { key = "bubbles", label = LT("Bubbles"), type = "int", min = 0, max = 5, default = 3 }, { key = "pulse", label = LT("Pulse"), type = "int", min = 1, max = 3, default = 2 }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local blit_rgb, snapshot, blit_indexed = gfx.blit_rgb, gfx.snapshot, gfx.blit_indexed local floor, sin, sqrt, abs, min, max = math.floor, math.sin, math.sqrt, math.abs, math.min, math.max local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local KEY = { 255, 0, 255 } local function mix(a, b, t) return floor(a[1] + (b[1] - a[1]) * t + 0.5), floor(a[2] + (b[2] - a[2]) * t + 0.5), floor(a[3] + (b[3] - a[3]) * t + 0.5) end local TONES = { violet = { 150, 98, 196, 214, 156, 238, 244, 204, 252, 255, 240, 255, 176, 124, 216, 210, 164, 236, aura = { 150, 100, 220 }, led = { 200, 120, 255 } }, cyan = { 70, 150, 190, 130, 214, 230, 190, 242, 250, 240, 255, 255, 100, 176, 206, 150, 220, 236, aura = { 80, 180, 220 }, led = { 90, 220, 255 } }, pink = { 196, 84, 140, 244, 150, 196, 255, 206, 228, 255, 240, 248, 214, 112, 160, 246, 170, 206, aura = { 230, 110, 170 }, led = { 255, 120, 190 } }, } local PAL, AURA, LEDC = nil, TONES.violet.aura, TONES.violet.led local SW, SH = 16, 22 local function make(w, h, tlen, amp) local g = {} for y = 1, SH do g[y] = {}; for x = 1, SW do g[y][x] = 0 end end for r = 0, h - 1 do local hw = w / 2 * sqrt(1 - (1 - (r + 0.7) / h) ^ 2) for x = 0, SW - 1 do local dx = x + 0.5 - 8 if abs(dx) <= hw then g[r + 1][x + 1] = (abs(dx) > hw - 1 or r == h - 1) and 1 or ((dx < -hw * 0.25) and 3 or 2) end end end local hx = floor(8 - (w / 2) * 0.55) g[2][hx + 1], g[2][hx + 2] = 4, 4 for x = 0, SW - 1 do if g[h][x + 1] ~= 0 and x % 2 == 0 then g[h][x + 1] = 0 end end local ks = { -(w / 2 - 1.5), -w / 4, w / 4, w / 2 - 1.5 } for i = 1, 4 do for j = 0, tlen - (i % 2) * 2 - 1 do local x = floor(8 + ks[i] + amp * sin(j * 0.55 + i * 1.7) + 0.5) if x >= 0 and x < SW and h + j + 1 <= SH then g[h + j + 1][x + 1] = 5 end end end for j = 0, floor(tlen * 0.55) do local off = (j // 2) % 2 for _, x in ipairs({ 7 + off, 8 + off }) do if h + j + 1 <= SH then g[h + j + 1][x + 1] = 6 end end end local rows = {} for y = 1, SH do rows[y] = string.char(table.unpack(g[y])) end return table.concat(rows) end local POSE local function poses() POSE = { make(12, 6, 13, 1.2), make(9, 7, 15, 0.6), make(14, 5, 10, 1.8) } end local BACK, FRONT local function bake() rect(0, 0, W, H, 20, 24, 38) for y = 10, 49 do rect(15, y, 34, 1, mix({ 30, 40, 110 }, { 18, 20, 64 }, (y - 10) / 39)) end rect(15, 46, 34, 4, 84, 72, 134); rect(15, 46, 34, 1, 112, 98, 164); rect(15, 48, 34, 2, 66, 56, 108) for k = 1, 8 do local h = hash32(k * 0x9E3779B1) px(16 + umod(h, 32), 47 + umod(h >> 8, 3), 140, 124, 190) end BACK = snapshot(0, 0, W, H) rect(0, 0, W, H, KEY[1], KEY[2], KEY[3]) rect(6, 7, 3, 46, 84, 70, 132); rect(6, 7, 1, 46, 140, 122, 200); rect(8, 7, 1, 46, 56, 46, 96) rect(6, 5, 7, 3, 84, 70, 132); rect(6, 5, 7, 1, 140, 122, 200) rect(12, 6, 40, 1, 150, 130, 210); rect(12, 7, 40, 2, 104, 86, 164); rect(12, 9, 40, 1, 70, 58, 120) rect(28, 3, 8, 3, 104, 86, 164); rect(28, 3, 8, 1, 150, 130, 210) rect(14, 10, 1, 40, 120, 136, 220); rect(15, 10, 1, 40, 52, 64, 140) rect(49, 10, 1, 40, 96, 108, 190); rect(48, 10, 1, 40, 40, 50, 120) rect(17, 14, 1, 17, 110, 132, 226); rect(17, 33, 1, 3, 110, 132, 226); rect(19, 14, 1, 3, 150, 168, 240) rect(44, 13, 3, 1, 200, 210, 255); rect(46, 14, 1, 2, 200, 210, 255) rect(54, 12, 4, 36, 122, 104, 176); rect(55, 13, 2, 34, 22, 26, 60) for y = 16, 44, 7 do rect(54, y, 1, 1, 220, 214, 255) end rect(10, 50, 44, 1, 150, 130, 210); rect(10, 51, 44, 1, 122, 104, 176) rect(10, 52, 44, 6, 84, 70, 132); rect(10, 58, 44, 1, 56, 46, 96) rect(6, 59, 52, 3, 70, 58, 120); rect(6, 59, 52, 1, 110, 92, 168) rect(0, 62, W, 2, 10, 12, 20) rect(34, 53, 16, 4, 12, 16, 30) for _, x in ipairs({ 13, 17, 21 }) do rect(x - 1, 53, 4, 4, 56, 46, 96) end FRONT = snapshot(0, 0, W, H) end local function ss(x) if x <= 0 then return 0 elseif x >= 1 then return 1 end return x * x * (3 - 2 * x) end local YBOT = 24 local function swim(t, pp) local m = t % (5 * pp + 5.5) if m < 5 * pp then local n = floor(m / pp) local u = (m - n * pp) / pp local rise = n * 2.2 + 3 * ss((u - 0.12) / 0.28) - 0.8 * ss((u - 0.4) / 0.6) local pose = (u < 0.12 and 1) or (u < 0.4 and 2) or (u < 0.55 and 1) or (u < 0.88 and 3) or 1 return pose, rise, (u >= 0.12 and u < 0.4) and sin((u - 0.12) / 0.28 * 3.1416) or 0 end return 1, 11 * (1 - ss((m - 5 * pp) / 5.5)), 0 end local BUB = {} for i = 1, 15 do local h = hash32(i * 0xC2B2AE35) BUB[i] = { x = 17 + umod(h, 30), v = 6 + umod(h >> 8, 7), off = umod(h >> 12, 400) / 10, ph = umod(h >> 20, 628) / 100, big = i % 4 == 0 } end function on_settings() local T = TONES[cfg.tone] or TONES.violet PAL = { 0, 0, 0, table.unpack(T) } AURA, LEDC = T.aura, T.led if not POSE then poses() end end local LEDG, LEDA = { 60, 230, 110 }, { 255, 176, 60 } local function led(x, c, on) local k = on and 1 or 0.2 rect(x, 54, 2, 2, floor(c[1] * k), floor(c[2] * k), floor(c[3] * k)) end function render() if not BACK then bake() end local t = frame / FPS local pp = 1.8 / (0.8 + 0.25 * ((cfg.pulse or 2) - 1)) local pose, rise, thrust = swim(t, pp) blit_rgb(BACK, 0, 0, W, H) local y = YBOT - floor(rise + 0.5) local a = AURA local gy = y + 3 for dy = -10, 10 do local hw = floor(sqrt(100.5 - dy * dy)) blend_rect(32 - hw, gy + dy, 2 * hw, 1, a[1], a[2], a[3], 0.05 + 0.06 * thrust) end for i = 1, 3 * (cfg.bubbles or 3) do local b = BUB[i] local yy = 46 - ((t * b.v + b.off) % 38) local iy = floor(yy) local f = yy - iy local x = floor(b.x + 1.2 * sin(t * 0.9 + b.ph) + 0.5) local w = b.big and 2 or 1 blend_rect(x, iy, w, 1, 190, 214, 255, 0.8 * (1 - f)) blend_rect(x, iy + 1, w, 1, 190, 214, 255, 0.8 * f) end blit_indexed(POSE[pose], PAL, 24, y, SW, SH, SW, SH, true) blit_rgb(FRONT, 0, 0, W, H, KEY[1], KEY[2], KEY[3]) led(13, LEDG, (t % 4) < 3.2) led(17, LEDA, (t * 2) % 3 < 0.5 or ((t * 2) % 3 > 1 and (t * 2) % 3 < 1.5)) led(21, LEDC, thrust > 0) local g = 6 + floor(rise / 11 * 26 + 0.5) rect(55, 46 - g, 2, g, 170, 120, 240) for c = 0, 15 do local _, _, th = swim(t - (15 - c) * 0.09, pp) px(34 + c, 56 - floor(th * 3 + 0.5), 90, 230, 200) end end