info = { type = "image", title = "Volcano", category = "nature", author = "BRRRO", version = "1.0", license = "MIT", desc = "A volcano erupts with arcing lava and smoke", api = 41, } local tr = ({ sk = { ["Eruption power"] = "Sila erupcie", ["Lava"] = "Láva", ["orange"] = "oranžová", ["red"] = "červená", ["toxic green"] = "jedovatá zelená" }, cs = { ["Eruption power"] = "Síla erupce", ["Lava"] = "Láva", ["orange"] = "oranžová", ["red"] = "červená", ["toxic green"] = "jedovatá zelená" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "power", label = T("Eruption power"), type = "int", min = 1, max = 5, default = 3 }, { key = "lava", label = T("Lava"), type = "int", default = 0, opts = { T("orange"), T("red"), T("toxic green") } }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sin, sqrt = math.floor, math.sin, math.sqrt local hash32 = math.hash32 local W, H = gfx.W, gfx.H local PALS = { { { 255, 232, 130 }, { 255, 150, 40 }, { 232, 76, 30 }, { 150, 42, 28 }, { 176, 56, 22 }, { 255, 100, 24 }, { 255, 176, 48 } }, { { 255, 170, 140 }, { 255, 70, 60 }, { 200, 30, 50 }, { 120, 24, 44 }, { 160, 28, 34 }, { 255, 40, 50 }, { 255, 96, 80 } }, { { 220, 255, 140 }, { 110, 240, 60 }, { 40, 170, 60 }, { 24, 100, 50 }, { 40, 130, 50 }, { 80, 255, 80 }, { 150, 255, 90 } }, } local P = PALS[1] local SKY = { 20, 14, 44 } local STAR, STAR_DIM = { 214, 214, 255 }, { 100, 98, 156 } local ROCK = { { { 146, 60, 28 }, { 116, 44, 26 } }, { { 104, 52, 34 }, { 80, 38, 30 } }, { { 76, 44, 38 }, { 58, 34, 34 } }, } local CX, CY = 32, 29 local SLOPE = 0.9 local G = 76.5 local function c3(c) return c[1], c[2], c[3] end local HWL, HWR = {}, {} for y = 30, H - 1 do local base = 4 + (y - 30) * SLOPE HWL[y] = floor(base + (hash32(y * 0x9E3779B1) & 3) / 3 + 0.3) HWR[y] = floor(base + (hash32(y * 0x85EBCA6B) & 3) / 3 + 0.3) end local STREAMS = { { 29, -1, 0.55, 0.0 }, { 35, 1, 0.38, 1.7 }, { 37, 1, 0.82, 3.1 } } local SX, SW = {}, {} for s = 1, 3 do local st = STREAMS[s] SX[s], SW[s] = {}, {} for y = 31, H - 1 do local d = y - 31 SX[s][y] = floor(st[1] + st[2] * d * st[3] + 1.6 * sin(d * 0.37 + st[4])) SW[s][y] = 1 + d // 14 end end local STX, STY, STP = {}, {}, {} do local k, i = 0, 0 while k < 12 and i < 100 do i = i + 1 local h = hash32(i * 0x9E3779B1) local x, y = (h & 0x7FFF) % W, ((h >> 8) & 0x7FFF) % 20 if (x > CX and x - CX or CX - x) > 14 or y < 5 then k = k + 1 STX[k], STY[k], STP[k] = x, y, ((h >> 16) & 0x7FFF) % 628 / 100.0 end end end local BG = nil local function build_bg() rect(0, 0, W, H, c3(SKY)) for y = 30, H - 1 do local z = y < 38 and 1 or (y < 50 and 2 or 3) local x0, x1 = CX - HWL[y], CX + HWR[y] local bx = CX + (y - 30) // 4 rect(x0, y, bx - x0, 1, c3(ROCK[z][1])) rect(bx, y, x1 - bx, 1, c3(ROCK[z][2])) end for i = 1, 46 do local h = hash32(i * 0xC2B2AE35) local y = 33 + (h & 0x7FFF) % 30 local x = CX - HWL[y] + 1 + ((h >> 9) & 0x7FFF) % (HWL[y] + HWR[y] - 2) local z = y < 38 and 1 or (y < 50 and 2 or 3) local c = ROCK[z][(h >> 20) & 1 == 0 and 1 or 2] if (h >> 21) & 1 == 0 then px(x, y, c[1] * 6 // 5, c[2] * 6 // 5, c[3] * 6 // 5) else px(x, y, c[1] * 3 // 4, c[2] * 3 // 4, c[3] * 3 // 4) end end for s = 1, 3 do for y = 31, H - 1 do rect(SX[s][y], y, SW[s][y], 1, c3(P[5])) end end rect(CX - 6, CY, 3, 1, c3(ROCK[1][1])) rect(CX + 4, CY, 3, 1, c3(ROCK[1][2])) rect(CX - 3, CY, 7, 1, c3(P[7])) rect(CX - 4, CY + 1, 9, 1, c3(P[1])) BG = gfx.snapshot(0, 0, W, H) end local GLOW = {} do for k, r in ipairs({ { 20, 14 }, { 13, 10 }, { 8, 6 } }) do local rows = {} for dy = 1, r[2] do rows[dy] = floor(r[1] * sqrt(1 - ((dy - 0.5) / r[2]) ^ 2)) end GLOW[k] = rows end end local GLOW_A = { 0.06, 0.09, 0.15 } local NP = 46 local PID, PX0, PVX, PVY, PTL, PDL, PPER = {}, {}, {}, {}, {}, {}, {} for i = 1, 72 do PID[i] = -1; PPER[i] = 2.67 - (i % 4) * 0.033 end local function launch(i, id) local h = hash32(i * 7919 + id * 104729) & 0x7FFF local sgn = (h & 1) == 0 and 1 or -1 local sp = 1.5 + ((h >> 1) % 48) * 0.3 local vy = -(30 + ((h >> 8) % 11) * 3) local dx0 = (h >> 5) % 3 PX0[i], PVX[i], PVY[i] = CX + sgn * dx0, sgn * sp, vy local A, B, C = 0.5 * G, vy - sp / SLOPE, (CY - 30) - (dx0 - 4) / SLOPE local r2 = (-B + sqrt(B * B - 4 * A * C)) / (2 * A) local t30 = (-vy + sqrt(vy * vy + 2 * G * (30 - CY))) / G PTL[i] = r2 > t30 and r2 or t30 PDL[i] = ((h >> 9) % 8) * 0.033 local env = 0.5 + 0.5 * sin(id * 1.7 + i * 0.9) PID[i] = id return ((h >> 12) % 100) < (45 + 55 * env) * ((cfg.power or 3) / 3.0) + 10 end local ACTIVE = {} local function clock(f) local c = data.time if c.ok then return c.unix % 3600 + c.ms / 1000 end return f end local function draw_stone(i, f) local per = PPER[i] local t0 = f + i * 0.367 local id, tau = floor(t0 / per), t0 % per if PID[i] ~= id then ACTIVE[i] = launch(i, id) end if not ACTIVE[i] then return end tau = tau - PDL[i] if tau < 0 then return end local tl = PTL[i] local x0, vx, vy = PX0[i], PVX[i], PVY[i] if tau <= tl then local a = tau / tl local k = a < 0.3 and 1 or (a < 0.65 and 2 or 3) local c = P[k] local x = x0 + vx * tau local y = CY + vy * tau + 0.5 * G * tau * tau if i % 3 == 0 then rect(floor(x), floor(y), 2, 2, c3(c)) else px(floor(x + 0.5), floor(y + 0.5), c3(c)) end if tau > 0.067 then local t1, t2 = tau - 0.067, tau - 0.133 local c1, c2 = P[k + 1], P[k + 2 > 4 and 4 or k + 2] px(floor(x0 + vx * t1 + 0.5), floor(CY + vy * t1 + 0.5 * G * t1 * t1 + 0.5), c3(c1)) if tau > 0.133 then px(floor(x0 + vx * t2 + 0.5), floor(CY + vy * t2 + 0.5 * G * t2 * t2 + 0.5), c3(c2)) end end elseif tau < tl + 0.47 then local e = tau - tl local c = e < 0.133 and P[2] or (e < 0.3 and P[3] or P[4]) px(floor(x0 + vx * tl + 0.5), floor(CY + vy * tl + 0.5 * G * tl * tl + 0.5) - 1, c3(c)) end end local PUFFS = 7 local SMOKE_HOT, SMOKE = { 140, 66, 46 }, { 92, 78, 98 } local function draw_smoke(f) for k = 0, PUFFS - 1 do local per = 5.6 local tau = (f + k * (per / PUFFS)) % per local u = tau / per local sz = 4 + floor(u * 12) local x = floor(CX - sz / 2 + 3 * sin(k * 2.3) + tau * 3) local y = floor(CY - 4 - tau * 6 - sz / 2) local a = (u < 0.08 and u / 0.08 or 1 - (u - 0.08) / 0.92) * 0.55 local c = tau < 1.2 and SMOKE_HOT or SMOKE if a > 0.03 then blend_rect(x + 1, y, sz - 2, sz, c[1], c[2], c[3], a) blend_rect(x, y + 1, 1, sz - 2, c[1], c[2], c[3], a) blend_rect(x + sz - 1, y + 1, 1, sz - 2, c[1], c[2], c[3], a) end end end function on_settings() P = PALS[(cfg.lava or 0) + 1] or PALS[1] BG = nil NP = 16 + 10 * (cfg.power or 3) for i = 1, 72 do PID[i] = -1 end end function render() if not BG then build_bg() end local f = frame / gfx.FPS gfx.blit_rgb(BG, 0, 0, W, H) local pul = 0.75 + 0.25 * sin(f * 3.3) + 0.1 * sin(f * 9.3 + 1) local pw = 0.6 + 0.2 * (cfg.power or 3) local gc = P[6] for k = 1, 3 do local rows, a = GLOW[k], GLOW_A[k] * pul * pw for dy = 1, #rows do local w = rows[dy] blend_rect(CX - w, CY - dy, 2 * w, 1, gc[1], gc[2], gc[3], a) end end for k = 1, #STX do local c = sin(f * 2.1 + STP[k] * 3) > -0.2 and STAR or STAR_DIM px(STX[k], STY[k], c3(c)) end for y = 30, 38 do blend_rect(CX - HWL[y], y, HWL[y] + HWR[y], 1, gc[1], gc[2], gc[3], (0.2 - (y - 30) * 0.02) * pul * pw) end local pc = P[1] for s = 1, 3 do for n = 0, 1 do local yh = 31 + (f * (6.6 + 1.2 * s) + n * 20 + s * 9) % 44 for y = floor(yh - 5), floor(yh) + 1 do if y >= 31 and y < H then local d = yh - y local a = d >= 0 and (d < 5 and 1 - d / 5 or 0) or (d > -1 and 1 + d or 0) if a > 0.05 then blend_rect(SX[s][y], y, SW[s][y], 1, pc[1], pc[2], pc[3], a * 0.85) end end end end end px(CX - 2 + floor(f * 6) % 5, CY, c3(P[1])) draw_smoke(f) local fc = clock(f) for i = 1, NP do draw_stone(i, fc) end end