info = { type = "image", title = "Lattice pie", category = "food", author = "BRRRO", version = "1.0", license = "MIT", desc = "Hot lattice pie with rising steam", api = 33, } local STEP_HZ = 30 local FSTEP = 0 local tr = ({ sk = { ["Filling"] = "Náplň", ["Cherry"] = "Čerešňa", ["Blueberry"] = "Čučoriedková", ["Apricot"] = "Marhuľová", ["Steam wisps"] = "Pramienky pary", ["Cloth"] = "Obrus" }, cs = { ["Filling"] = "Náplň", ["Cherry"] = "Třešeň", ["Blueberry"] = "Borůvková", ["Apricot"] = "Meruňková", ["Steam wisps"] = "Prameny páry", ["Cloth"] = "Ubrus" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "fruit", label = T("Filling"), type = "int", default = "cherry", opts = { keys = { "cherry", "blueberry", "apricot" }, T("Cherry"), T("Blueberry"), T("Apricot") } }, { key = "steam", label = T("Steam wisps"), type = "int", min = 0, max = 4, default = 3 }, { key = "cloth", label = T("Cloth"), type = "color", default = "#D63C40" }, } local rect, px, brect = gfx.rect, gfx.px, gfx.blend_rect local floor, ceil, sin, sqrt = math.floor, math.ceil, math.sin, math.sqrt local TAU = 6.28318 local FRUIT = { cherry = { { 184, 22, 48 }, { 124, 14, 34 }, { 255, 150, 164 }, { 206, 26, 52 }, { 132, 14, 36 } }, blueberry = { { 76, 66, 158 }, { 46, 38, 106 }, { 190, 184, 255 }, { 84, 76, 176 }, { 50, 42, 118 } }, apricot = { { 236, 140, 40 }, { 176, 92, 24 }, { 255, 228, 150 }, { 244, 150, 46 }, { 184, 98, 26 } }, } local FR = FRUIT.cherry local PX, PY, PW, PH = 4, 32, 54, 24 local YBOT = 56 local BGG, BGP, PIG, PIP, FRG, FRP = "", { 0, 0, 0 }, "", { 0, 0, 0 }, "", { 0, 0, 0 } local BU = {} local GAPS = {} local function build() local ZERO = { 0 } do local n = 1 while n < 64 do table.move(ZERO, 1, n, n + 1); n = n * 2 end end local pal, pidx, cv = { 0, 0, 0 }, {}, {} local cw, ch, ox, oy = 64, 64, 0, 0 local function C(r, g, b) r, g, b = floor(r + 0.5), floor(g + 0.5), floor(b + 0.5) r = r > 255 and 255 or r; g = g > 255 and 255 or g; b = b > 255 and 255 or b local k = r * 65536 + g * 256 + b local i = pidx[k] if not i then i = #pal // 3 pidx[k] = i local n = #pal pal[n + 1], pal[n + 2], pal[n + 3] = r, g, b end return i end local function reset(w, h, x0, y0) cw, ch, ox, oy = w, h, x0, y0 for y = 1, h do cv[y] = table.move(ZERO, 1, w, 1, cv[y] or {}) end end local function fill(r, a, n, c) r[a] = c local k = 1 while k < n do local m = (k <= n - k) and k or (n - k) table.move(r, a, a + m - 1, a + k) k = k + m end end local function R(x, y, w, h, c) x, y = x - ox, y - oy local xa, xb = (x < 0 and 0 or x), (x + w - 1 > cw - 1 and cw - 1 or x + w - 1) local ya, yb = (y < 0 and 0 or y), (y + h - 1 > ch - 1 and ch - 1 or y + h - 1) if xa > xb or ya > yb then return end local n = xb - xa + 1 local o = xa + 1 if n >= 12 then local r = cv[ya + 1] fill(r, o, n, c) for yy = ya + 2, yb + 1 do table.move(r, o, o + n - 1, o, cv[yy]) end else for yy = ya + 1, yb + 1 do local r = cv[yy] for i = o, o + n - 1 do r[i] = c end end end end local function E(cx, cy, rx, ry, c) for y = floor(cy - ry), ceil(cy + ry) - 1 do local dy = (y + 0.5 - cy) / ry local q = 1 - dy * dy if q >= 0 then local hw = rx * sqrt(q) local x0 = ceil(cx - hw - 0.5) R(x0, y, floor(cx + hw - 0.5) - x0 + 1, 1, c) end end end local function P(x, y, c) R(x, y, 1, 1, c) end local function bake() local rows = {} for y = 0, ch - 1 do rows[y + 1] = string.char(table.unpack(cv[y + 1], 1, cw)) end return table.concat(rows), pal end local function inE(x, y, cx, cy, rx, ry) local a, b = (x + 0.5 - cx) / rx, (y + 0.5 - cy) / ry return a * a + b * b <= 1 end local cl = cfg.cloth or { r = 214, g = 60, b = 64 } local WALL, WALL_D, WALL_L = C(150, 92, 64), C(128, 74, 52), C(176, 116, 80) local LIGHT = C(252, 244, 240) local MID = C(cl.r * 0.45 + 252 * 0.55, cl.g * 0.45 + 244 * 0.55, cl.b * 0.45 + 240 * 0.55) local DARK = C(cl.r * 0.75, cl.g * 0.75, cl.b * 0.75) local SHAD = C(cl.r * 0.42, cl.g * 0.42, cl.b * 0.42) reset(64, 64, 0, 0) R(0, 0, 64, 24, WALL) R(0, 14, 64, 10, WALL_D) R(0, 14, 64, 1, WALL_L) local g1, g2 = {}, {} for x = 0, 63 do local a = (x // 4) % 2 == 0 g1[x + 1] = a and DARK or MID g2[x + 1] = a and MID or LIGHT end for y = 24, 63 do table.move((y // 4) % 2 == 0 and g1 or g2, 1, 64, 1, cv[y + 1]) end R(0, 24, 64, 1, DARK) E(32.5, 53.5, 29, 7, SHAD) BGG, BGP = bake() pal, pidx = { 0, 0, 0 }, {} FR = FRUIT[cfg.fruit or "cherry"] or FRUIT.cherry local FILL, FILL_D = C(FR[1][1], FR[1][2], FR[1][3]), C(FR[2][1], FR[2][2], FR[2][3]) local DISH, DISH_D = C(188, 200, 222), C(118, 130, 158) local CR, CR_L, CR_D = C(214, 152, 74), C(236, 184, 100), C(176, 112, 52) local LA, LB = C(244, 198, 112), C(224, 168, 86) reset(PW, PH, PX, PY) E(30.5, 45, 25.5, 11, DISH_D) E(30.5, 44, 25.5, 11, DISH) E(30.5, 43.5, 23, 9.7, CR_D) GAPS, BU = {}, {} for y = 33, 52 do local q1 = 1 - ((y + 0.5 - 42.5) / 8.4) ^ 2 local q2 = 1 - ((y + 0.5 - 43.5) / 9.7) ^ 2 if q2 >= 0 then local h2 = 23 * sqrt(q2) local h1 = q1 >= 0 and 21.2 * sqrt(q1) or -1 local xo0, xo1 = ceil(30.5 - h2 - 0.5), floor(30.5 + h2 - 0.5) local xi0, xi1 = ceil(30.5 - h1 - 0.5), floor(30.5 + h1 - 0.5) local r, o = cv[y - PY + 1], 1 - PX for x = xo0, xo1 do if x >= xi0 and x <= xi1 then local d, s = x + y, x - y if d % 7 < 3 then r[o + x] = LA elseif s % 7 < 3 then r[o + x] = LB else r[o + x] = (((d - 1) % 7 < 3) or ((s - 1) % 7 < 3)) and FILL_D or FILL GAPS[#GAPS + 1] = { x, y } local bk = BU[d] if not bk then bk = {}; BU[d] = bk end bk[#bk + 1] = x; bk[#bk + 1] = y end else r[o + x] = ((x + y) % 3 == 0) and CR_L or CR end end end end PIG, PIP = bake() pal, pidx = { 0, 0, 0 }, {} reset(14, 14, 47, 47) local FB, FD = C(FR[4][1], FR[4][2], FR[4][3]), C(FR[5][1], FR[5][2], FR[5][3]) local ST, ST_L = C(70, 120, 60), C(110, 168, 86) E(54.5, 55.5, 5.5, 5.5, FD) E(54, 55, 5.5, 5.5, FB) E(55.5, 57, 3.2, 3, FD) R(53, 49, 2, 1, ST); R(55, 48, 2, 1, ST); R(57, 47, 2, 1, ST) R(53, 50, 3, 1, ST_L) P(51, 52, C(255, 220, 224)); P(51, 53, C(255, 220, 224)); P(52, 52, C(255, 220, 224)) FRG, FRP = bake() end function on_settings() build() end local function hash(a) return math.hash32(a * 0x9E3779B1) end function render() FSTEP = frame * STEP_HZ // gfx.FPS local t = FSTEP gfx.blit_indexed(BGG, BGP, 0, 0, 64, 64, 64, 64) local h = floor(25 + 1.4 * sin(t * 0.055) + 0.5) gfx.blit_indexed(PIG, PIP, PX, YBOT - h, PW, h, PW, PH, true) gfx.blit_indexed(FRG, FRP, 47, 47, 14, 14, 14, 14, true) local top = YBOT - h local u = 38 + (t % 130) local g = FR[3] for du = -1, 1 do local bk = BU[u + du] if bk then for i = 1, #bk, 2 do local y = top + floor((bk[i + 1] - PY + 0.5) * h / PH) if du == 0 then px(bk[i], y, g[1], g[2], g[3]) else brect(bk[i], y, 1, 1, g[1], g[2], g[3], 0.55) end end end end local n = #GAPS for k = 1, 2 do local ph = (t + k * 31) % 60 if ph < 12 then local q = GAPS[1 + hash(((t + k * 31) // 60) * 7 + k) % n] local y = top + floor((q[2] - PY + 0.5) * h / PH) px(q[1], y, g[1], g[2], g[3]) if ph > 5 then brect(q[1] - 1, y, 3, 1, g[1], g[2], g[3], 0.35) end end end local fp = (t + 20) % 90 if fp < 7 then if fp >= 2 and fp < 5 then rect(49, 53, 5, 1, 255, 255, 255) rect(51, 51, 1, 5, 255, 255, 255) else px(51, 53, 255, 255, 255) end end local N = cfg.steam or 3 local L = 90 for k = 1, N do local xk = 8 + (k - 0.5) * 48 / N for p = 0, 7 do local a = (t * 0.6 + p * (L / 8) + k * 17) % L local x = xk + 2.6 * sin(a * 0.09 + k * 2.1) local y = 38 - a * 0.4 local al = 0.42 * sin(3.1416 * a / L) local w = 2 + (a > 30 and 1 or 0) + (a > 60 and 1 or 0) brect(floor(x), floor(y), w, 4, 255, 252, 246, al) end end end