info = { type = "image", title = "Jelly rise", category = "animals", author = "BRRRO", version = "1.0", license = "MIT", desc = "Jellyfish pulse upward, tentacles trailing", api = 33, } local ltr = ({ sk = { ["Jelly colour"] = "Farba želé", ["Jellyfish"] = "Medúzy", ["Bubbles"] = "Bubliny" }, cs = { ["Jelly colour"] = "Barva želé", ["Jellyfish"] = "Medúzy", ["Bubbles"] = "Bubliny" }, })[lang] or {} local function LT(s) return ltr[s] or s end settings = { { key = "tone", label = LT("Jelly colour"), type = "color", default = "#FF86C2" }, { key = "count", label = LT("Jellyfish"), type = "int", min = 1, max = 3, default = 2 }, { key = "bubbles", label = LT("Bubbles"), type = "bool", default = true }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sin, sqrt, exp = math.floor, math.sin, math.sqrt, math.exp local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local TAU = 6.28318 local SAND = 58 local function water(y) local t = y / (H - 1) return floor(150 - 86 * t), floor(226 - 100 * t), floor(232 - 56 * t) end local function mix(c, d, k) return { floor(c[1] + (d[1] - c[1]) * k + 0.5), floor(c[2] + (d[2] - c[2]) * k + 0.5), floor(c[3] + (d[3] - c[3]) * k + 0.5) } end local WHITE = { 255, 255, 255 } local BG = nil local function build_bg() for y = 0, H - 1 do rect(0, y, W, 1, water(y)) end for k, x0 in ipairs({ 6, 22, 41, 55 }) do for y = 0, 30 do local a = 0.16 * (1 - y / 34) blend_rect(x0 + y // 3, y, 3 + (k % 2), 1, 255, 255, 255, a) end end for x = 0, W - 1 do local h = floor(3 + 1.6 * sin(x * 0.11 + 1) + 1.2 * sin(x * 0.27) + 0.5) rect(x, H - h - 1, 1, h + 1, 214, 200, 156) px(x, H - h - 1, 236, 224, 182) end rect(9, 59, 5, 3, 120, 124, 140); rect(10, 58, 3, 1, 120, 124, 140); px(10, 58, 160, 164, 178) rect(47, 60, 7, 2, 120, 124, 140); rect(48, 59, 4, 1, 160, 164, 178) BG = gfx.snapshot(0, 0, W, H) end local function hline(x0, x1, y, c, a) local i0, i1 = floor(x0), floor(x1) if i1 <= i0 then blend_rect(i0, y, 1, 1, c[1], c[2], c[3], a * (x1 - x0)); return end local wl, wr = i0 + 1 - x0, x1 - i1 if i1 - i0 > 1 then blend_rect(i0 + 1, y, i1 - i0 - 1, 1, c[1], c[2], c[3], a) end blend_rect(i0, y, 1, 1, c[1], c[2], c[3], a * wl) if wr > 0.03 then blend_rect(i1, y, 1, 1, c[1], c[2], c[3], a * wr) end end local function soft(x0, y0, x1, y1, r, g, b, a) local ix0, iy0, ix1, iy1 = floor(x0), floor(y0), floor(x1), floor(y1) local mw, mh = ix1 - ix0 - 1, iy1 - iy0 - 1 local wl, wr, wt, wb = ix0 + 1 - x0, x1 - ix1, iy0 + 1 - y0, y1 - iy1 if mw > 0 and mh > 0 then blend_rect(ix0 + 1, iy0 + 1, mw, mh, r, g, b, a) end if mh > 0 then if wl > 0.03 then blend_rect(ix0, iy0 + 1, 1, mh, r, g, b, a * wl) end if wr > 0.03 then blend_rect(ix1, iy0 + 1, 1, mh, r, g, b, a * wr) end end if mw > 0 then if wt > 0.03 then blend_rect(ix0 + 1, iy0, mw, 1, r, g, b, a * wt) end if wb > 0.03 then blend_rect(ix0 + 1, iy1, mw, 1, r, g, b, a * wb) end end end local JEL = { { R = 9, P = 68, D = 7.5, x0 = 30, ax = 4, px = 520, y0 = 30, ph = 0, depth = 0, nt = 6, nl = 15 }, { R = 6, P = 56, D = 5.0, x0 = 50, ax = 3, px = 430, y0 = 70, ph = 23, depth = 0.4, nt = 5, nl = 11 }, { R = 4, P = 48, D = 3.6, x0 = 13, ax = 2, px = 380, y0 = 10, ph = 9, depth = 0.65, nt = 4, nl = 8 }, } local SPAN = H + 46 local function squeeze(u) if u < 0.22 then return sin(u / 0.22 * 1.5708) end local v = (u - 0.22) / 0.78 return 1 - v * v * (3 - 2 * v) end local K6 = 1 - exp(-6) local function rise(J, tt) local n = tt // J.P local u = (tt % J.P) / J.P return J.y0 - J.D * (n + (1 - exp(-6 * u)) / K6) end local ROWC = {} local COL = {} local function colours(c) local base = { c.r, c.g, c.b } for i = 1, #JEL do local d = JEL[i].depth local wr, wg, wb = water(28) local b = mix(base, { wr, wg, wb }, d * 0.55) COL[i] = { mix(b, WHITE, 0.62), mix(b, WHITE, 0.12), mix(b, WHITE, 0.4), b, mix(b, { 180, 30, 110 }, 0.3), 0.86 - d * 0.35 } ROWC[i] = {} end end local ST, CT, SA, CA = {}, {}, {}, {} for s = 1, 16 do ST[s], CT[s] = sin(s * 0.4), math.cos(s * 0.4) SA[s], CA[s] = sin(s * 0.6), math.cos(s * 0.6) end local YS, XS, WS = {}, {}, {} local function bell_rows(i, BH) local R = ROWC[i] local list = R[BH] if not list then list = {} local C = COL[i] for r = 0, BH - 1 do list[r] = mix(C[1], C[2], (r + 0.5) / BH) end R[BH] = list end return list end local function jelly(i, t) local J = JEL[i] local C = COL[i] local tt = t + J.ph * 7 local Y = rise(J, tt) local off = ((Y + 40) % SPAN) - 40 - Y local y = Y + off local P, R = J.P, J.R local c = squeeze((tt % P) / P) local wx, hy = 1 - 0.2 * c, 1 + 0.2 * c local xc = J.x0 + J.ax * sin(tt * TAU / J.px) local BH = floor(R * 0.9 * hy + 0.5) local a = C[6] local iy = floor(y) local f = y - iy local nt, nl = J.nt, J.nl for s = 1, nl do local ts = tt - s * 2 YS[s] = rise(J, ts) + off + R * 0.9 XS[s] = J.x0 + J.ax * sin(ts * TAU / J.px) WS[s] = R * 0.82 * (1 - 0.2 * squeeze((ts % P) / P)) end local tc = C[3] local tr, tg, tb = tc[1], tc[2], tc[3] for k = 0, nt - 1 do local side = (k / (nt - 1)) * 2 - 1 local A = t * 0.09 + k * 1.7 local sA, cA = sin(A), math.cos(A) local py = floor(YS[1] + 0.5) for s = 2, nl, 2 do local xs = XS[s] + side * WS[s] + (sA * CT[s] - cA * ST[s]) * s * 0.09 local yy = floor(YS[s] + s * 1.15 + 0.5) if yy <= py then yy = py + 1 end blend_rect(floor(xs + 0.5), py + 1, 1, yy - py, tr, tg, tb, a * (0.8 - 0.55 * s / nl)) py = yy end end local ac = C[4] for k = -1, 1 do local A = t * 0.12 + k * 2.1 local sA, cA = sin(A), math.cos(A) local py = floor(YS[1] + 0.5) for s = 2, nl // 2 + 3, 2 do local xs = XS[s] + k * R * 0.25 + (sA * CA[s] - cA * SA[s]) * (0.6 + s * 0.12) local yy = floor(YS[s] + s + 0.5) if yy <= py then yy = py + 1 end local w = (s < 4) and 2 or 1 blend_rect(floor(xs + 0.5) - (w - 1), py + 1, w, yy - py, ac[1], ac[2], ac[3], a * 0.8) py = yy end end local rows = bell_rows(i, BH) for r = 0, BH - 1 do local v = (r + 0.5) / BH local hw = R * wx * sqrt(1 - (1 - v) * (1 - v)) if r == BH - 1 then hw = hw + 0.6 end hline(xc - hw, xc + hw, iy + r, rows[r], (r == 0) and a * (1 - f) or a) end if f > 0.03 then local hw = R * wx + 0.6 hline(xc - hw, xc + hw, iy + BH, C[2], a * f) end local gc = C[5] hline(xc - R * wx * 0.7, xc + R * wx * 0.7, iy + BH - 1, gc, a * 0.5) if R >= 6 then local gy = iy + floor(BH * 0.5) hline(xc - R * 0.42, xc + R * 0.42, gy + 1, gc, a * 0.55) hline(xc - R * 0.25, xc + R * 0.25, gy, gc, a * 0.45) hline(xc - R * 0.55, xc - R * 0.1, iy + 2, WHITE, 0.55 * a) end end local BUB = {} for k = 1, 7 do local h = hash32(k * 0x9E3779B1) BUB[k] = { x = 4 + umod(h, W - 8), v = 0.25 + umod(h >> 8, 30) / 100, off = umod(h >> 16, 200), s = 1.3 + umod(h >> 4, 10) / 10, ph = umod(h >> 20, 628) / 100 } end local function bubbles(t) for k = 1, #BUB do local b = BUB[k] local span = SAND + 8 local y = SAND - ((t * b.v + b.off) % span) local x = b.x + sin(t * 0.07 + b.ph) * 1.4 local s = b.s * (1 + (SAND - y) / 90) soft(x - s / 2, y - s / 2, x + s / 2, y + s / 2, 240, 252, 255, 0.55) if s > 1.8 then px(floor(x - s / 4), floor(y - s / 4), 255, 255, 255) end end end local N, BUBS = 2, true function on_settings() colours(cfg.tone or { r = 255, g = 134, b = 194 }) N = cfg.count or 2 BUBS = cfg.bubbles ~= false end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local t = frame * STEP_HZ // FPS for i = N, 1, -1 do jelly(i, t) end if BUBS then bubbles(t) end end