info = { type = "image", title = "Deep sea", category = "animals", author = "BRRRO", version = "1.1", license = "MIT", desc = "Bioluminescent jellyfish in the deep", api = 33, } local blend, rect, blend_rect = gfx.blend, gfx.rect, gfx.blend_rect local WATER = nil local floor, ceil, abs, sin, cos, sqrt, fmod = math.floor, math.ceil, math.abs, math.sin, math.cos, math.sqrt, math.fmod local PI2 = 2 * math.pi local W, H = gfx.W, gfx.H local FPS = gfx.FPS local MAX_JELLY, N_FLAKE = 5, 26 local ltr = ({ sk = { ["Jellyfish count"] = "Počet medúz", ["Marine snow"] = "Morský sneh", ["particles that keep falling in the deep"] = "častice, ktoré stále padajú do hlbín", ["Speed"] = "Rýchlosť", ["„random“ = changes by itself"] = "„náhodne“ = mení sa samo", ["random"] = "náhodne", ["slow"] = "pomaly", ["medium"] = "stredne", ["fast"] = "rýchlo", ["Visitor"] = "Návštevník", ["now and then something passes through"] = "občas niečo prejde", ["none"] = "žiadne", ["submarine"] = "ponorka", ["deep-sea fish"] = "hlbokomorské ryby", ["alternating"] = "striedavo", ["Jellyfish colour"] = "Farba medúz", ["„original“ = bioluminescent mix"] = "„pôvodná“ = bioluminiscenčná zmes", ["original"] = "pôvodná", ["lava"] = "láva", ["turquoise"] = "tyrkysová", ["pink"] = "ružová", ["green"] = "zelená", ["purple"] = "fialová", ["blue"] = "modrá", ["gold"] = "zlatá", ["red"] = "červená" }, cs = { ["Jellyfish count"] = "Počet medúz", ["Marine snow"] = "Mořský sníh", ["particles that keep falling in the deep"] = "částice, které stále padají do hlubin", ["Speed"] = "Rychlost", ["„random“ = changes by itself"] = "„náhodně“ = mění se samo", ["random"] = "náhodně", ["slow"] = "pomalu", ["medium"] = "středně", ["fast"] = "rychle", ["Visitor"] = "Návštěvník", ["now and then something passes through"] = "občas něco projde", ["none"] = "žádné", ["submarine"] = "ponorka", ["deep-sea fish"] = "hlubinné ryby", ["alternating"] = "střídavě", ["Jellyfish colour"] = "Barva medúz", ["„original“ = bioluminescent mix"] = "„původní“ = bioluminiscenční směs", ["original"] = "původní", ["lava"] = "láva", ["turquoise"] = "tyrkysová", ["pink"] = "růžová", ["green"] = "zelená", ["purple"] = "fialová", ["blue"] = "modrá", ["gold"] = "zlatá", ["red"] = "červená" }, })[lang] or {} local function LT(s) return ltr[s] or s end settings = { { key = "jellies", type = "int", default = 3, min = 1, max = 5, label = LT("Jellyfish count") }, { key = "snow", type = "bool", default = true, label = LT("Marine snow"), hint = LT("particles that keep falling in the deep") }, { key = "speed", type = "int", default = "slow", label = LT("Speed"), hint = LT("„random“ = changes by itself"), opts = { keys = { "random", "slow", "medium", "fast" }, LT("random"), LT("slow"), LT("medium"), LT("fast") } }, { key = "guest", type = "int", default = "mixed", label = LT("Visitor"), hint = LT("now and then something passes through"), opts = { keys = { "none", "sub", "fish", "mixed" }, LT("none"), LT("submarine"), LT("deep-sea fish"), LT("alternating") } }, { key = "hue", type = "int", default = "original", label = LT("Jellyfish colour"), hint = LT("„original“ = bioluminescent mix"), opts = { keys = { "original", "random", "lava", "turquoise", "pink", "green", "purple", "blue", "gold", "red" }, LT("original"), LT("random"), LT("lava"), LT("turquoise"), LT("pink"), LT("green"), LT("purple"), LT("blue"), LT("gold"), LT("red") } }, } local rng = 0x1BD11BDA local function rnd() rng = (rng ~ (rng << 13)) & 0xFFFFFFFF rng = rng ~ (rng >> 17) rng = (rng ~ (rng << 5)) & 0xFFFFFFFF return rng end local umod = math.umod local function frnd(a, b) return a + (b - a) * (umod(rnd(), 1000) / 999.0) end local SP_HOLD_MIN, SP_HOLD_SPAN = FPS * 25, FPS * 60 local a_cur, a_tgt, a_hold = 1.0, 1.0, 0 local LVL = { random = 0, slow = 1, medium = 2, fast = 3 } local function auto_level(opt, n) if opt > 0 and opt <= n then a_cur, a_tgt, a_hold = opt - 1, opt - 1, 0; return a_cur end if a_hold == 0 then local sp = n - 1 for i = 1, 8 do local t = umod(rnd(), 1000) / 999.0 * sp if abs(t - a_tgt) >= sp * 0.30 then a_tgt = t; break end if i == 8 then a_tgt = sp - a_tgt end end a_hold = SP_HOLD_MIN + umod(rnd(), SP_HOLD_SPAN) end a_hold = a_hold - 1 a_cur = a_cur + (a_tgt - a_cur) * (0.096 / FPS) return a_cur end local function amb_lerp(v, n, t) if t <= 0 then return v[1] end if t >= n - 1 then return v[n] end local i = floor(t) return v[i + 1] + (v[i + 2] - v[i + 1]) * (t - i) end local PAL_N = 8 local PALS = { { lo = { 255, 105, 25 }, hi = { 255, 205, 70 } }, { lo = { 40, 215, 255 }, hi = { 150, 255, 235 } }, { lo = { 255, 85, 180 }, hi = { 255, 175, 230 } }, { lo = { 60, 235, 90 }, hi = { 180, 255, 140 } }, { lo = { 150, 80, 255 }, hi = { 215, 170, 255 } }, { lo = { 45, 120, 255 }, hi = { 130, 205, 255 } }, { lo = { 255, 170, 20 }, hi = { 255, 235, 120 } }, { lo = { 255, 55, 45 }, hi = { 255, 150, 90 } }, } local PAL_AT = { lava = 1, turquoise = 2, pink = 3, green = 4, purple = 5, blue = 6, gold = 7, red = 8 } local OWN = { 90, 240, 255, 180, 120, 255, 255, 130, 205, 120, 255, 205 } local PC = { 90, 240, 255, 180, 120, 255, 255, 130, 205, 120, 255, 205 } local A_FADE = 0.0070 local A_HOLD_MIN, A_HOLD_SPAN = FPS * 30, FPS * 60 local p_from, p_to, p_t, p_hold = 1, 1, 1.0, 0 local function set_shades(lr, lg, lb, hr, hg, hb) PC[1], PC[2], PC[3] = lr, lg, lb PC[4] = lr + (hr - lr) * 0.45 PC[5] = lg + (hg - lg) * 0.45 PC[6] = lb + (hb - lb) * 0.45 PC[7], PC[8], PC[9] = hr, hg, hb PC[10] = hr + (255 - hr) * 0.25 PC[11] = hg + (255 - hg) * 0.25 PC[12] = hb + (255 - hb) * 0.25 end local function step_pal(opt) if opt == "original" then for i = 1, 12 do PC[i] = OWN[i] end return end local fixed = PAL_AT[opt] if fixed then local p = PALS[fixed] set_shades(p.lo[1], p.lo[2], p.lo[3], p.hi[1], p.hi[2], p.hi[3]) return end if p_t >= 1.0 then if p_hold > 0 then p_hold = p_hold - 1 local p = PALS[p_to] set_shades(p.lo[1], p.lo[2], p.lo[3], p.hi[1], p.hi[2], p.hi[3]) return end p_from = p_to local n repeat n = umod(rnd(), PAL_N) + 1 until n ~= p_from p_to, p_t = n, 0.0 end p_t = p_t + A_FADE if p_t > 1.0 then p_t = 1.0; p_hold = A_HOLD_MIN + umod(rnd(), A_HOLD_SPAN) end local f, t = PALS[p_from], PALS[p_to] set_shades(f.lo[1] + (t.lo[1] - f.lo[1]) * p_t, f.lo[2] + (t.lo[2] - f.lo[2]) * p_t, f.lo[3] + (t.lo[3] - f.lo[3]) * p_t, f.hi[1] + (t.hi[1] - f.hi[1]) * p_t, f.hi[2] + (t.hi[2] - f.hi[2]) * p_t, f.hi[3] + (t.hi[3] - f.hi[3]) * p_t) end local function lvl3(c, lvl) local k = lvl * (1.0 / 255.0) return floor(c[1] * k), floor(c[2] * k), floor(c[3] * k) end local function shade3(o, lvl) local r, g, b = PC[o + 1], PC[o + 2], PC[o + 3] local m = r; if g > m then m = g end; if b > m then m = b end local k = lvl / m return floor(r * k), floor(g * k), floor(b * k) end local function sub_px(x, yf, r, g, b) local yi = floor(yf) local f = yf - yi if f < 0.02 then blend(x, yi, r, g, b, 1.0) return end local s = f * f * (3 - 2 * f) blend(x, yi, r, g, b, sqrt(1 - s)) if s > 0.004 then blend(x, yi + 1, r, g, b, sqrt(s)) end end local function sub_x(xf, y, r, g, b) local xi = floor(xf) local f = xf - xi local s = f * f * (3 - 2 * f) blend(xi, y, r, g, b, sqrt(1 - s)) if s > 0.004 then blend(xi + 1, y, r, g, b, sqrt(s)) end end local function vspan(x, ya, yb, r, g, b) if yb <= ya then return end local ia, ib = floor(ya), floor(yb) if ia == ib then blend(x, ia, r, g, b, yb - ya) return end blend(x, ia, r, g, b, ia + 1 - ya) if ib - ia > 1 then rect(x, ia + 1, 1, ib - ia - 1, r, g, b) end local f = yb - ib if f > 0.01 then blend(x, ib, r, g, b, f) end end local FAR_C = { 18, 50, 100 } local NEAR_C = { 50, 42, 112 } local NEAR_D = { 34, 30, 84 } local RIM_C = { 100, 94, 188 } local NEAR_Y = H - 2 local ROCKS = { { 4, 9, 7, 3 }, { 17, 5, 3, 2 }, { 30, 7, 5, 4 }, { 45, 9, 9, 2.5 }, { 59, 6, 4, 3 } } local function near_top(x) local top = NEAR_Y for i = 1, #ROCKS do local r = ROCKS[i] local q = abs(x - r[1]) / r[2] if q < 1 then local y = NEAR_Y - r[3] * sqrt(1 - q ^ r[4]) + 0.5 * sin(x * 1.9 + i) if y < top then top = y end end end return top end local function draw_static() for y = 0, H - 1 do local b = floor(120 - 82 * y / (H - 1) + 0.5) rect(0, y, W, 1, 2, floor(b * 0.22 + 0.5), b) end for x = 0, W - 1 do local hf = H - 11 + 2.5 * sin(x * 0.11 + 0.7) + 1.5 * sin(x * 0.29 + 2.1) vspan(x, hf, H, FAR_C[1], FAR_C[2], FAR_C[3]) local hn = near_top(x) if hn < NEAR_Y then vspan(x, hn, ceil(hn), NEAR_C[1], NEAR_C[2], NEAR_C[3]) local hd = H - hn for y = ceil(hn), H - 1 do local t = (y - hn) / hd local k = ((x * 7 + y * 13) ~ (x * y)) % 11 == 0 and 0.86 or 1.0 rect(x, y, 1, 1, floor((NEAR_C[1] + (NEAR_D[1] - NEAR_C[1]) * t) * k), floor((NEAR_C[2] + (NEAR_D[2] - NEAR_C[2]) * t) * k), floor((NEAR_C[3] + (NEAR_D[3] - NEAR_C[3]) * t) * k)) end else vspan(x, hn, H, NEAR_D[1], NEAR_D[2], NEAR_D[3]) end sub_px(x, hn, RIM_C[1], RIM_C[2], RIM_C[3]) end end local RAY_X = { 4, 25, 46 } local RAY_L = { 40, 30, 44 } local RAY_A = { 0.17, 0.12, 0.15 } local RAY_C = { 110, 205, 255 } local t_sea = 0 local function draw_rays() local cr, cg, cb = RAY_C[1], RAY_C[2], RAY_C[3] for i = 1, 3 do local x0 = RAY_X[i] + 0.8 * sin(t_sea * 0.37 + i) local sl = 0.32 + 0.05 * sin(t_sea * 0.21 + i * 2.1) local a0 = RAY_A[i] * (0.75 + 0.25 * sin(t_sea * 0.33 + i * 1.3)) local L = RAY_L[i] for y = 0, L - 1 do local f = y / L local a = a0 * (1 - f) local c, w = x0 + y * sl, 1.4 + 2.6 * f local xl, xr = c - w, c + w local il, ir = ceil(xl), floor(xr) if ir > il then blend_rect(il, y, ir - il, 1, cr, cg, cb, a) end blend(il - 1, y, cr, cg, cb, a * (il - xl)) blend(ir, y, cr, cg, cb, a * (xr - ir)) end end end local AN_X, AN_H = { 6, 26, 42, 53 }, { 4, 3, 5, 3 } local AN_Y = {} for i = 1, #AN_X do AN_Y[i] = floor(near_top(AN_X[i]) + 0.5) end local function draw_anemones() for i = 1, #AN_X do local o = ((i - 1) % 4) * 3 local sw = 1.5 * sin(t_sea * 0.8 + i * 1.7) local h, by = AN_H[i], AN_Y[i] local sr, sg, sb = shade3(o, 120) for k = 1, h do local f = k / h sub_x(AN_X[i] + sw * f * f, by - k, sr, sg, sb) end local tx, ty = AN_X[i] + sw, by - h local lr, lg, lb = shade3(o, 205 + 50 * sin(t_sea * 1.3 + i * 2.3)) local s2 = sw * 0.3 sub_x(tx - 1, ty, sr, sg, sb) sub_x(tx + 1, ty, sr, sg, sb) sub_x(tx + s2, ty - 1, sr, sg, sb) sub_x(tx - 2 + s2, ty - 1, lr, lg, lb) sub_x(tx + 2 + s2, ty - 1, lr, lg, lb) sub_x(tx + 2 * s2, ty - 2, lr, lg, lb) blend(floor(tx + 2 * s2 + 0.5), ty - 3, lr, lg, lb, 0.35) end end local NB = 9 local VENT_X = 38 local VENT_Y = floor(near_top(VENT_X)) local BUB_S, BUB_B = { lvl3({ 170, 225, 255 }, 230) }, { lvl3({ 170, 225, 255 }, 130) } local bx, by, bph, bon = {}, {}, {}, {} for i = 1, NB do bon[i] = false end local b_wait, b_left = 2 * FPS, 4 local function step_bubbles(m) local dt = m / FPS for i = 1, NB do if bon[i] then local big = by[i] < VENT_Y - 18 by[i] = by[i] - (big and 8.5 or 5.5) * dt bph[i] = bph[i] + 2.4 * dt if by[i] < -3 then bon[i] = false end end end b_wait = b_wait - m if b_wait > 0 then return end for i = 1, NB do if not bon[i] then bon[i], bx[i], by[i], bph[i] = true, VENT_X + frnd(-0.5, 0.5), VENT_Y - 1, frnd(0, PI2) break end end b_left = b_left - 1 if b_left > 0 then b_wait = frnd(6, 15) else b_left = 3 + umod(rnd(), 5); b_wait = frnd(4, 12) * FPS end end local function draw_bubbles() local sr, sg, sb = BUB_S[1], BUB_S[2], BUB_S[3] local dr, dg, db = BUB_B[1], BUB_B[2], BUB_B[3] for i = 1, NB do if bon[i] then local x, y = floor(bx[i] + 0.8 * sin(bph[i]) + 0.5), by[i] if y < VENT_Y - 18 then sub_px(x, y, sr, sg, sb) sub_px(x + 1, y, dr, dg, db) sub_px(x, y + 1, dr, dg, db) else sub_px(x, y, sr, sg, sb) end end end end local jx, jy, jph, jsp, jwob, jshade, jsize, jlayer = {}, {}, {}, {}, {}, {}, {}, {} local jc = {} local RIM_L = { 205, 235, 255 } local MRG_L = { 150, 180, 210 } local ORG_L = { 230, 250, 255 } local TNT_L = { 140, 165, 190 } local JSIZE = { 4, 6, 8 } local TENT_U = { -0.85, -0.48, 0.48, 0.85 } local SINK_PS, THRUST_PS = 1.65, 5.70 local DRIFT_PS, WOB_RS = 3.00, 0.36 local SPEED_MUL = { 0.90, 1.50, 2.30 } local function place_jelly(i) local layer = 2 - ((i - 1) % 3) jlayer[i] = layer jsize[i] = JSIZE[layer + 1] jx[i] = frnd(6, W - 6) jy[i] = frnd(4, H - 12) jph[i] = frnd(0, PI2) jsp[i] = 0.90 + 0.36 * umod(rnd(), 3) jwob[i] = frnd(0, PI2) jshade[i] = umod(rnd(), 4) * 3 end for i = 1, MAX_JELLY do place_jelly(i) jc[i] = { 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0 } end local function step_jelly(i, m) local dt = m / FPS jph[i] = fmod(jph[i] + jsp[i] * dt, PI2) jwob[i] = fmod(jwob[i] + WOB_RS * dt, PI2) local thrust = -cos(jph[i]) if thrust < 0 then thrust = 0 end local y = jy[i] + (SINK_PS - THRUST_PS * thrust) * dt local x = jx[i] + DRIFT_PS * dt * sin(jwob[i]) local sz = jsize[i] local tail, head = 2 * sz + 4, sz + 2 if y < -tail then y = H + head elseif y > H + head then y = -tail end local hw = sz + 6 if x < -hw then x = W + hw elseif x > W + hw then x = -hw end jx[i], jy[i] = x, y end local function tint_jelly(i) local c, o, L = jc[i], jshade[i], jlayer[i] + 1 c[1], c[2], c[3] = shade3(o, RIM_L[L]) c[4], c[5], c[6] = shade3(o, MRG_L[L]) c[7], c[8], c[9] = shade3(o, ORG_L[L]) c[10], c[11], c[12] = shade3(o, TNT_L[L]) c[13] = c[7] + (255 - c[7]) * 0.6 c[14] = c[8] + (255 - c[8]) * 0.6 c[15] = c[9] + (255 - c[9]) * 0.6 end local function draw_jelly(i) local c = jc[i] local sz = jsize[i] local p = sin(jph[i]) local rx = sz * (1.00 + 0.20 * p) local ry = sz * (0.78 - 0.20 * p) local cx, cy = jx[i], jy[i] local x0, x1 = ceil(cx - rx), floor(cx + rx) local mr = 0.22 * ry for X = x0, x1 do local q = (X - cx) / rx if q < -1 then q = -1 elseif q > 1 then q = 1 end local w = sqrt(1 - q * q) local ya, yb = floor(cy - ry * w + 1.5), floor(cy + mr * w + 0.5) if yb > ya then blend_rect(X, ya, 1, yb - ya, c[1], c[2], c[3], 0.12 + 0.16 * w) end blend(X, floor(cy - ry * w - 0.5), c[1], c[2], c[3], 0.30) sub_px(X, cy - ry * w, c[1], c[2], c[3]) sub_px(X, cy + mr * w, c[4], c[5], c[6]) end sub_px(x0, cy, c[7], c[8], c[9]) sub_px(x1, cy, c[7], c[8], c[9]) local oy = cy - ry * 0.45 sub_px(floor(cx - rx * 0.42 + 0.5), oy, c[7], c[8], c[9]) sub_px(floor(cx + rx * 0.42 + 0.5), oy, c[7], c[8], c[9]) if sz >= 6 then for k = 0, 1 do local q = -0.62 + 0.24 * k sub_px(floor(cx + rx * q + 0.5), cy - ry * sqrt(1 - q * q) + 1, c[13], c[14], c[15]) end end local len = sz * 2 + 2 local base = jph[i] * 0.7 for t = 1, 4 do local u = TENT_U[t] local tx = cx + rx * u local ty = cy + mr * sqrt(1 - u * u) local ph = base + t * 1.1 for k = 1, len do local f = k / len local yy = ty + k if yy >= H then break end if f < 0.68 or (k % 2) == 0 then sub_px(floor(tx + 3.6 * f * f * sin(ph + f * 4.2) + 0.5), yy, c[10], c[11], c[12]) end end end local alen = floor(sz * 1.5 + 1) for s = -1, 1, 2 do for k = 1, alen do local f = k / alen local yy = cy + mr + k if yy >= H then break end sub_px(floor(cx + s * (0.4 + 0.9 * f) * sin(base * 1.4 + f * 5.0) + 0.5), yy, c[4], c[5], c[6]) end end end local SNOW = { 206, 233, 255 } local FL_LVL = { 190, 215, 240 } local FL_VPS = { 0.80, 1.50, 2.50 } local FL_COL = {} for k = 1, 3 do FL_COL[k] = { lvl3(SNOW, FL_LVL[k]) } end local fx, fy, fwob, fcls = {}, {}, {}, {} for i = 1, N_FLAKE do fcls[i] = ((i - 1) % 3) + 1 fx[i], fy[i], fwob[i] = frnd(0, W), frnd(0, H), frnd(0, PI2) end local function step_snow(m) local dt = m / FPS for i = 1, N_FLAKE do local y = fy[i] + FL_VPS[fcls[i]] * dt fwob[i] = fmod(fwob[i] + 0.90 * dt, PI2) if y > floor(near_top(fx[i])) then y = -2; fx[i] = frnd(0, W) end fy[i] = y end end local function draw_snow() for i = 1, N_FLAKE do local k = fcls[i] local c = FL_COL[k] local x = floor(fx[i] + 1.5 * sin(fwob[i]) + 0.5) if k == 3 then vspan(x, fy[i], fy[i] + 2.0, c[1], c[2], c[3]) else sub_px(x, fy[i], c[1], c[2], c[3]) end end end local G_MIN, G_SPAN = 10, 30 local gon, gkind, gx, gy, gsp, gph, gright = false, 0, 0, 0, 0, 0, true local next_guest, last_frame = G_MIN * FPS + umod(rnd(), G_SPAN * FPS), 0 local function step_guest(m) local dt = m / FPS if gon then gx = gx + (gright and gsp or -gsp) * dt gph = fmod(gph + 0.60 * dt, PI2) if gx < -26 or gx > W + 26 then gon = false next_guest = frame + (40 + umod(rnd(), 80)) * FPS end return end if frame < next_guest then return end gon = true local g = cfg.guest or "mixed" gkind = (g == "mixed") and (rnd() & 1) or (g == "fish" and 1 or 0) gright = (rnd() & 1) == 1 gsp = (gkind == 0) and frnd(4.8, 7.8) or frnd(3.0, 5.4) gx = gright and -22 or (W + 22) gy = frnd(14, H - 22) gph = frnd(0, PI2) end local SUB = { 162, 201, 255 } local WIN = { 255, 205, 110 } local LAMP = { 255, 248, 210 } local BEAM = { 170, 225, 255 } local HULL_RX, HULL_RY, BEAM_LEN = 8.5, 2.7, 15 local function draw_sub(cx, cy, dir) local lx = cx + dir * HULL_RX for X = ceil(cx - HULL_RX), floor(cx + HULL_RX) do local q = (X - cx) / HULL_RX if q < -1 then q = -1 elseif q > 1 then q = 1 end local h = HULL_RY * sqrt(1 - q * q) if h > 0.15 then local lv = 104 + 101 * (1 - abs(X - lx) / 7) if lv < 104 then lv = 104 end local r, g, b = lvl3(SUB, lv) vspan(X, cy - h, cy + h, r, g, b) local tl = lv + 50; if tl > 255 then tl = 255 end r, g, b = lvl3(SUB, tl) sub_px(X, cy - h, r, g, b) end end local tr, tg, tb = lvl3(SUB, 122) local hr, hg, hb = lvl3(SUB, 172) for d = -2, 1 do local X = floor(cx + (d - dir) + 0.5) vspan(X, cy - 5.4, cy - 2.6, tr, tg, tb) sub_px(X, cy - 5.4, hr, hg, hb) end vspan(floor(cx - dir * (HULL_RX + 1) + 0.5), cy - 3.2, cy + 3.2, tr, tg, tb) local wr, wg, wb = WIN[1], WIN[2], WIN[3] sub_px(floor(cx - dir * 3 + 0.5), cy - 0.5, wr, wg, wb) sub_px(floor(cx + 0.5), cy - 0.5, wr, wg, wb) sub_px(floor(lx + 0.5), cy, LAMP[1], LAMP[2], LAMP[3]) local bx0 = floor(lx + 0.5) for i = 1, BEAM_LEN do local t = i / BEAM_LEN local w = 0.9 + 3.4 * t local X = bx0 + dir * i local r, g, b = lvl3(BEAM, 191 - 86 * t) vspan(X, cy - w, cy + w, r, g, b) r, g, b = lvl3(BEAM, 245 - 110 * t) vspan(X, cy - w * 0.45, cy + w * 0.45, r, g, b) end end local FISH_LIT = { 185, 255, 212 } local FISH_EDGE = { 175, 195, 255 } local TOOTH = { 228, 239, 255 } local LURE = { 190, 255, 200 } local BAND_R = { 9.0, 6.6, 4.4, 2.2 } local BAND_L = { 135, 175, 215, 250 } local BAND_C = {} for k = 1, 4 do BAND_C[k] = { lvl3(FISH_LIT, BAND_L[k]) } end local BODY_C = { lvl3(FISH_EDGE, 104) } local EYE = { lvl3(FISH_EDGE, 255) } local EDGE_C = { lvl3(FISH_EDGE, 150) } local STALK_C = { lvl3(FISH_LIT, 175) } local GLOW_A = { lvl3(LURE, 175) } local GLOW_B = { lvl3(LURE, 118) } local function draw_angler(cx, cy, dir, ph) local lx = cx + dir * 9 local ly = cy - 5 + 0.8 * sin(ph * 2.0) local xa, xb = cx + dir * (-7), cx + dir * 5 if xa > xb then xa, xb = xb, xa end for X = ceil(xa), floor(xb) do local q = ((X - cx) * dir + 1.0) / 7.0 if q >= -1 and q <= 1 then local h = 3.6 * sqrt(1 - q * q) local ya, yb = cy - h, cy + h vspan(X, ya, yb, BODY_C[1], BODY_C[2], BODY_C[3]) vspan(X, ya, ya + 1, EDGE_C[1], EDGE_C[2], EDGE_C[3]) vspan(X, yb - 1, yb, EDGE_C[1], EDGE_C[2], EDGE_C[3]) local ddx = X - lx for k = 1, 4 do local rr = BAND_R[k] * BAND_R[k] - ddx * ddx if rr > 0 then local hy = sqrt(rr) local ba, bb = ly - hy, ly + hy if ba < ya then ba = ya end if bb > yb then bb = yb end local c = BAND_C[k] vspan(X, ba, bb, c[1], c[2], c[3]) end end end end for i = 0, 3 do local X = floor(cx - dir * (8 + i // 2) + 0.5) sub_px(X, cy - 2 - i, EDGE_C[1], EDGE_C[2], EDGE_C[3]) sub_px(X, cy + 2 + i, EDGE_C[1], EDGE_C[2], EDGE_C[3]) end for i = 0, 2 do sub_px(floor(cx + dir * (1 + 2 * i) + 0.5), cy + 2, TOOTH[1], TOOTH[2], TOOTH[3]) end sub_px(floor(cx + dir * 3 + 0.5), cy - 1, EYE[1], EYE[2], EYE[3]) sub_px(floor(cx + dir * 4 + 0.5), cy - 3, STALK_C[1], STALK_C[2], STALK_C[3]) sub_px(floor(cx + dir * 6 + 0.5), cy - 4, STALK_C[1], STALK_C[2], STALK_C[3]) sub_px(floor(cx + dir * 8 + 0.5), cy - 5, STALK_C[1], STALK_C[2], STALK_C[3]) local ix = floor(lx + 0.5) sub_px(ix - 1, ly, GLOW_A[1], GLOW_A[2], GLOW_A[3]) sub_px(ix + 1, ly, GLOW_A[1], GLOW_A[2], GLOW_A[3]) sub_px(ix, ly - 1, GLOW_A[1], GLOW_A[2], GLOW_A[3]) sub_px(ix, ly + 1, GLOW_A[1], GLOW_A[2], GLOW_A[3]) sub_px(ix - 1, ly - 1, GLOW_B[1], GLOW_B[2], GLOW_B[3]) sub_px(ix + 1, ly - 1, GLOW_B[1], GLOW_B[2], GLOW_B[3]) sub_px(ix - 1, ly + 1, GLOW_B[1], GLOW_B[2], GLOW_B[3]) sub_px(ix + 1, ly + 1, GLOW_B[1], GLOW_B[2], GLOW_B[3]) sub_px(ix, ly, LURE[1], LURE[2], LURE[3]) end function update() if frame < last_frame then gon = false next_guest = frame + G_MIN * FPS + umod(rnd(), G_SPAN * FPS) end last_frame = frame step_pal(cfg.hue or "original") local m = amb_lerp(SPEED_MUL, 3, auto_level(LVL[cfg.speed] or 1, 3)) t_sea = t_sea + m / FPS local n = cfg.jellies or 3 if n > MAX_JELLY then n = MAX_JELLY elseif n < 1 then n = 1 end for i = 1, n do step_jelly(i, m) tint_jelly(i) end if cfg.snow then step_snow(m) end step_bubbles(m) if cfg.guest ~= "none" then step_guest(m) else gon = false end end function render() if not WATER then draw_static() WATER = gfx.snapshot(0, 0, W, H) end gfx.blit_rgb(WATER, 0, 0, W, H) draw_rays() if cfg.snow then draw_snow() end if gon then local cy = gy + 1.2 * sin(gph) local dir = gright and 1 or -1 if gkind == 0 then draw_sub(gx, cy, dir) else draw_angler(gx, cy, dir, gph) end end draw_anemones() draw_bubbles() local n = cfg.jellies or 3 if n > MAX_JELLY then n = MAX_JELLY elseif n < 1 then n = 1 end for layer = 0, 2 do for i = 1, n do if jlayer[i] == layer then draw_jelly(i) end end end end