info = { type = "image", title = "Boiling pot", category = "food", author = "BRRRO", version = "1.0", license = "MIT", desc = "Stove with a bubbling pot and a hopping lid", api = 33, } local tr = ({ sk = { ["Boil"] = "Var", ["Lid hop"] = "Skákanie pokrievky", ["Off"] = "Vypnuté", ["Rare"] = "Zriedka", ["Often"] = "Často", ["Lively"] = "Čulo", ["Pot colour"] = "Farba hrnca", ["Blue"] = "Modrá", ["Red"] = "Červená", ["Teal"] = "Tyrkysová", ["Gold"] = "Zlatá" }, cs = { ["Boil"] = "Var", ["Lid hop"] = "Skákání poklice", ["Off"] = "Vypnuto", ["Rare"] = "Zřídka", ["Often"] = "Často", ["Lively"] = "Čile", ["Pot colour"] = "Barva hrnce", ["Blue"] = "Modrá", ["Red"] = "Červená", ["Teal"] = "Tyrkysová", ["Gold"] = "Zlatá" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "boil", label = T("Boil"), type = "int", min = 1, max = 5, default = 3 }, { key = "hop", label = T("Lid hop"), type = "int", default = 2, opts = { T("Off"), T("Rare"), T("Often"), T("Lively") } }, { key = "pot", label = T("Pot colour"), type = "int", default = "blue", opts = { keys = { "blue", "red", "teal", "gold" }, T("Blue"), T("Red"), T("Teal"), T("Gold") } }, } local rect, blend_rect = gfx.rect, gfx.blend_rect local floor, sin, sqrt, max, min, abs = math.floor, math.sin, math.sqrt, math.max, math.min, math.abs local hash32, umod = math.hash32, math.umod local W, H = gfx.W, gfx.H local POTS = { blue = { 70, 122, 214 }, red = { 214, 72, 66 }, teal = { 52, 170, 158 }, gold = { 226, 176, 56 } } local TILE, GROUT = { 44, 62, 98 }, { 30, 44, 72 } local STEEL = { 150, 160, 188 } local KEY = { 255, 0, 255 } local function clamp(v) return v < 0 and 0 or (v > 255 and 255 or floor(v + 0.5)) end local function lit(c, u) local z = sqrt(max(0, 1 - u * u)) local d = max(0, -0.5 * u + 0.81 * z) local t = 0.34 + 0.78 * d + 0.14 * max(0, u - 0.55) local sp = max(0, 1 - abs(u + 0.42) / 0.11) sp = 170 * sp * sp * 0.5 return clamp(c[1] * t + sp), clamp(c[2] * t + sp), clamp(c[3] * t + sp) end local function cyl(x, y, w, h, c) for i = 0, w - 1 do rect(x + i, y, 1, h, lit(c, (i + 0.5) / w * 2 - 1)) end end local function ell(cx, cy, rx, ry, r, g, b) local ry5 = ry + 0.5 for dy = -floor(ry), floor(ry) do local hw = floor(rx * sqrt(1 - (dy / ry5) ^ 2) + 0.5) rect(cx - hw, cy + dy, 2 * hw + 1, 1, r, g, b) end end local LW, LH, LY0 = 29, 9, 13 local LID_HW = { 7, 10, 12, 13, 14, 14 } local function build_lid() rect(0, 0, LW, LH, KEY[1], KEY[2], KEY[3]) for i = 0, LW - 1 do local top = 8 for r = 1, #LID_HW do if abs(i - 14) <= LID_HW[r] then top = r + 1 break end end local r, g, b = lit(STEEL, (i + 0.5) / LW * 2 - 1) rect(i, top, 1, 8 - top, r, g, b) blend_rect(i, top, 1, 1, 255, 255, 255, 0.22) rect(i, 8, 1, 1, clamp(r * 0.6), clamp(g * 0.6), clamp(b * 0.62)) end rect(13, 0, 3, 2, 52, 58, 86) blend_rect(13, 0, 1, 2, 255, 255, 255, 0.25) return gfx.snapshot(0, 0, LW, LH) end local WX, WY, WW, WH = 38, 28, 12, 11 local POT_X, POT_W = 31, 27 local function build_bg(pc) rect(0, 0, W, 39, TILE[1], TILE[2], TILE[3]) for y = 5, 35, 6 do rect(0, y, W, 1, GROUT[1], GROUT[2], GROUT[3]) local off = ((y // 6) % 2) * 4 for x = off, W - 1, 8 do rect(x, y - 5, 1, 5, GROUT[1], GROUT[2], GROUT[3]) end end rect(0, 39, W, 1, 18, 24, 42) cyl(5, 16, 6, 11, { 96, 70, 120 }); cyl(7, 10, 2, 6, { 96, 70, 120 }); rect(7, 9, 2, 1, 168, 126, 92) cyl(13, 19, 7, 8, { 150, 170, 200 }); cyl(13, 17, 7, 2, { 206, 84, 76 }) cyl(21, 21, 6, 6, { 84, 156, 124 }) rect(2, 27, 26, 2, 120, 84, 78); rect(2, 29, 26, 1, 74, 52, 56) rect(62, 3, 1, 19, STEEL[1], STEEL[2], STEEL[3]); ell(62, 24, 1, 2, 130, 140, 168) for y = 40, 53 do local t = (y - 40) / 13 rect(0, y, W, 1, clamp(74 + 44 * t), clamp(78 + 46 * t), clamp(110 + 50 * t)) end rect(0, 54, W, 10, 84, 64, 128) rect(0, 54, W, 1, 132, 112, 178) for _, kx in ipairs({ 8, 20 }) do ell(kx, 59, 3, 3, 232, 222, 244) rect(kx - 1, 57, 1, 1, 255, 252, 255) rect(kx, 58, 1, 2, 84, 64, 128) rect(kx - 3, 62, 7, 1, 60, 46, 96) end rect(0, 42, 3, 2, 62, 62, 80) ell(13, 43, 11, 3, 52, 52, 66) ell(13, 43, 9, 2, 22, 22, 30) rect(3, 46, 20, 1, 36, 36, 48) ell(9, 43, 4, 1, 240, 238, 228) ell(17, 43, 3, 1, 240, 238, 228) rect(8, 42, 2, 1, 255, 196, 48); rect(17, 42, 2, 1, 255, 196, 48) rect(5, 49, 19, 2, 20, 22, 34) local lo = pc local dr, dg, db = lit(lo, 0.9) rect(28, 27, 3, 1, dr, dg, db); rect(28, 27, 1, 5, dr, dg, db); rect(28, 31, 3, 1, dr, dg, db) rect(58, 27, 3, 1, dr, dg, db); rect(60, 27, 1, 5, dr, dg, db); rect(58, 31, 3, 1, dr, dg, db) rect(30, 52, 29, 2, 20, 22, 34) rect(33, 46, 2, 6, 28, 28, 40); rect(42, 46, 2, 6, 28, 28, 40); rect(51, 46, 2, 6, 28, 28, 40) rect(POT_X, 21, POT_W, 1, 12, 14, 26) cyl(POT_X, 22, POT_W, 24, lo) blend_rect(POT_X, 22, POT_W, 1, 255, 255, 255, 0.28) blend_rect(POT_X, 26, POT_W, 1, 255, 255, 255, 0.12) blend_rect(POT_X, 43, POT_W, 3, 0, 0, 0, 0.3) rect(WX - 1, WY - 1, WW + 2, WH + 2, 24, 28, 48) for r = 0, WH - 1 do local t = r / (WH - 1) rect(WX, WY + r, WW, 1, clamp(170 - 130 * t), clamp(222 - 112 * t), clamp(246 - 62 * t)) end rect(WX, WY, WW, 1, 226, 244, 255) blend_rect(WX + 1, WY + 1, 1, WH - 3, 255, 255, 255, 0.3) return gfx.snapshot(0, 0, W, H) end local BG, LID local HOPP = { 0, 160, 100, 64 } local function lift(f) local P = HOPP[(cfg.hop or 2) + 1] if P == 0 then return 0 end local p = f % P if p < 12 then local u = p / 12; return 12.8 * u * (1 - u) end if p >= 14 and p < 22 then local u = (p - 14) / 8; return 5.2 * u * (1 - u) end return 0 end local WISP, BUB = {}, {} for i = 1, 14 do local h = hash32(i * 0x9E3779B1) WISP[i] = { x = 44 + umod(h, 17) - 8, v = 0.019 + umod(h >> 5, 6) / 1000, o = umod(h >> 9, 100) / 100, k = 1 + umod(h >> 13, 2), ph = umod(h >> 15, 628) / 100, w = 3 + umod(h >> 20, 2) } BUB[i] = { x = WX + 1 + umod(h >> 3, WW - 3), sp = 0.3 + umod(h >> 8, 26) / 100, o = umod(h >> 14, 100), big = (h >> 22) & 1 } end local FLAME = { { 190, 226, 255 }, { 96, 160, 255 }, { 52, 92, 236 }, { 36, 60, 200 } } local function flames(xs, base, rows, f) for k = 1, #xs do local h = 2.4 + 1.1 * sin(f * 0.37 + k * 1.9) + 0.8 * sin(f * 0.23 + k * 0.7) if h > rows then h = rows end for i = 1, 4 do local cover = min(1, h - (i - 1)) if cover <= 0.05 then break end local c = FLAME[i] if cover > 0.95 then rect(xs[k], base - i, 2, 1, c[1], c[2], c[3]) else blend_rect(xs[k], base - i, 2, 1, c[1], c[2], c[3], cover) end end end end local XR = { 31, 35, 37, 39, 44, 46, 48, 53, 55 } local XL = { 6, 9, 12, 15, 18, 21 } function render() if not BG then LID = build_lid() BG = build_bg(POTS[cfg.pot] or POTS.blue) end local f = frame local boil = cfg.boil or 3 gfx.blit_rgb(BG, 0, 0, W, H) flames(XR, 51, 4, f) flames(XL, 48, 3, f + 40) blend_rect(POT_X + 1, 44, POT_W - 2, 2, 120, 170, 255, 0.09 + 0.03 * sin(f * 0.3)) for i = 1, 2 * boil + 1 do local b = BUB[i] local y = WY + WH - 2 - ((f * b.sp + b.o) % (WH - 2)) local yi = floor(y) local fr = y - yi blend_rect(b.x, yi, 1 + b.big, 1, 240, 250, 255, 0.85 * (1 - fr)) blend_rect(b.x, yi + 1, 1 + b.big, 1, 240, 250, 255, 0.85 * fr) end if (f // 2) % 7 == 0 then rect(7, 44, 1, 1, 255, 244, 200) end if (f // 2 + 3) % 9 == 0 then rect(19, 44, 1, 1, 255, 244, 200) end local lf = lift(f) gfx.blit_rgb(LID, POT_X - 1, LY0 - floor(lf + 0.5), LW, LH, KEY[1], KEY[2], KEY[3]) local boost = 1 + 0.9 * min(1, lf / 2) for i = 1, 4 + 2 * boil do local s = WISP[i] local q = (f * s.v + s.o) % 1 local y = 12 - lf - q * 21 local x = floor(s.x + sin(q * 6.2832 * s.k + s.ph) * (1.2 + 3 * q) + 0.5) local w = s.w + floor(q * 4 + 0.5) local a = 0.3 * (1 - q) * min(1, q * 10) * boost local yi = floor(y) local fr = y - yi blend_rect(x - w // 2, yi, w, 1, 196, 210, 232, a * (1 - fr)) blend_rect(x - w // 2, yi + 1, w, 1, 196, 210, 232, a) blend_rect(x - w // 2, yi + 2, w, 1, 196, 210, 232, a * fr) end end