info = { type = "image", title = "Sushi belt", category = "food", author = "BRRRO", version = "1.0", license = "MIT", desc = "Conveyor-belt sushi, chopsticks grab a plate", api = 33, } local tr = ({ sk = { ["Speed"] = "Rýchlosť", ["Chopsticks"] = "Paličky" }, cs = { ["Speed"] = "Rychlost", ["Chopsticks"] = "Hůlky" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "speed", label = T("Speed"), type = "int", min = 1, max = 5, default = 3 }, { key = "grab", label = T("Chopsticks"), type = "bool", default = true }, } local rect, px, blend_rect, blend = gfx.rect, gfx.px, gfx.blend_rect, gfx.blend local blit_rgb, snapshot = gfx.blit_rgb, gfx.snapshot local floor, sin, sqrt, min, max = math.floor, math.sin, math.sqrt, math.min, math.max local hash32, umod = math.hash32, math.umod local char = string.char local W, H = gfx.W, gfx.H local WALL, WALL_L = { 64, 70, 118 }, { 52, 58, 100 } local BELT = { 122, 80, 56 } local MIST = { 255, 244, 230 } local function c3(c) return c[1], c[2], c[3] end local PW, PH = 20, 10 local FOOD = { { 250, 246, 236 }, { 255, 138, 92 }, { 255, 182, 138 }, { 196, 52, 72 }, { 232, 100, 116 }, { 252, 212, 96 }, { 40, 56, 48 }, { 126, 196, 100 }, { 250, 150, 110 }, { 255, 236, 220 } } local KEY = { w = 4, o = 5, O = 6, t = 7, T = 8, y = 9, n = 10, c = 11, e = 12, E = 13 } local TINT = { { { 250, 170, 188 }, { 255, 218, 226 }, { 206, 128, 150 } }, { { 160, 220, 200 }, { 220, 246, 238 }, { 112, 170, 156 } }, { { 200, 184, 240 }, { 238, 232, 252 }, { 150, 134, 196 } }, { { 250, 226, 150 }, { 255, 246, 214 }, { 204, 176, 100 } }, } local NIG = { ".OoOo.", "oOoOoO", "wwwwww", ".wwww." } local NIG_TUNA = { ".TtTt.", "tTtTtT", "wwwwww", ".wwww." } local NIG_EGG = { "yyynyy", "yyynyy", "wwwwww", ".wwww." } local NIG_EBI = { ".eEeE.", "eEeEeE", "wwwwww", ".wwww." } local MAKI = { ".nnn.", "nwcwn", "ncccn", "nwcwn", ".nnn." } local MAKI_S = { ".nnn.", "nwowo", "nooon", "nwowo", ".nnn." } local PIECES = { { { NIG, 3, 2 }, { NIG, 10, 2 } }, { { MAKI, 4, 1 }, { MAKI_S, 11, 1 } }, { { NIG_TUNA, 3, 2 }, { NIG_EGG, 10, 2 } }, { { NIG_EBI, 3, 2 }, { MAKI, 11, 1 } }, } local function inside(dx, dy, a, b) return (dx / a) ^ 2 + (dy / b) ^ 2 <= 1 end local CELLS = {} local function cells(ty) if CELLS[ty] then return CELLS[ty] end local g = {} for r = 0, PH - 1 do for c = 0, PW - 1 do local dx, dy = c + 0.5 - PW / 2, r + 0.5 - 4.3 local v = 0 if inside(dx, dy - 1, 9.8, 4.2) then v = 3 end if inside(dx, dy, 9.8, 4.2) then v = inside(dx, dy, 7.6, 2.7) and 2 or 1 end g[r * PW + c + 1] = v end end for _, p in ipairs(PIECES[ty]) do for r, row in ipairs(p[1]) do for c = 1, #row do local k = KEY[row:sub(c, c)] if k then g[(p[3] + r - 1) * PW + p[2] + c] = k end end end end CELLS[ty] = g return g end local RAS = {} local function plate(ty, ph) local key = ty * 4 + ph if RAS[key] then return RAS[key] end local g, f = cells(ty), ph / 4 local pal = TINT[ty] local function col(v) if v == 0 then return nil end return v <= 3 and pal[v] or FOOD[v - 3] end local out, n = {}, 0 for r = 0, PH - 1 do for x = 0, PW do local a = x > 0 and col(g[r * PW + x]) or nil local b = x < PW and col(g[r * PW + x + 1]) or nil local cr, cg, cb = 255, 0, 255 if a or b then local A, B = a or BELT, b or BELT cr, cg, cb = floor(A[1] * f + B[1] * (1 - f) + 0.5), floor(A[2] * f + B[2] * (1 - f) + 0.5), floor(A[3] * f + B[3] * (1 - f) + 0.5) end out[n + 1], out[n + 2], out[n + 3] = cr, cg, cb n = n + 3 end end RAS[key] = char(table.unpack(out)) return RAS[key] end local function put_plate(ty, x, y) local ix = floor(x) blit_rgb(plate(ty, floor((x - ix) * 4)), ix, y, PW + 1, PH, 255, 0, 255) end local BG local function bake() rect(0, 0, W, 22, c3(WALL)) for x = 7, W - 1, 8 do rect(x, 0, 1, 22, c3(WALL_L)) end local ww = { 4, 7, 8, 9, 9, 9, 8, 7, 4 } rect(9, 0, 1, 2, 40, 30, 36) rect(6, 2, 7, 1, 40, 30, 36) for i, w in ipairs(ww) do rect(9 - w // 2, 2 + i, w, 1, 255, 208, 122) if i >= 3 and i <= 7 then rect(9 - (w - 4) // 2, 2 + i, w - 4, 1, 255, 236, 170) end end rect(6, 12, 7, 1, 40, 30, 36) for _, x in ipairs({ 42, 48, 54 }) do rect(x + 2, 2, 1, 2, 40, 30, 36) rect(x, 4, 5, 12, 236, 222, 190) rect(x + 1, 6, 3, 2, 190, 50, 50) rect(x + 2, 9, 1, 4, 190, 50, 50) end rect(0, 22, W, 1, 190, 124, 80) rect(0, 23, W, 1, 150, 92, 60) rect(0, 24, W, 15, c3(BELT)) rect(0, 24, W, 1, 136, 92, 64) rect(0, 39, W, 2, 230, 176, 112) rect(0, 41, W, 3, 176, 112, 70) rect(0, 44, W, 1, 98, 60, 44) rect(0, 45, W, H - 45, 190, 128, 84) rect(0, 45, W, 1, 214, 156, 106) rect(0, 53, W, 1, 160, 102, 66) rect(0, 60, W, 1, 160, 102, 66) rect(36, 61, 24, 2, 150, 96, 62) for r = 0, 8 do local x0 = 38 + r * 0.7 // 1 rect(x0, 53 + r, 21 - 2 * (r * 0.7 // 1), 1, 176, 40, 48) rect(x0, 53 + r, 2, 1, 222, 90, 90) end rect(42, 61, 12, 1, 110, 26, 36) for y = 49, 53 do local dy = (y + 0.5 - 51) / 2.6 if dy * dy < 1 then local hw = 10.5 * sqrt(1 - dy * dy) rect(floor(48.5 - hw + 0.5), y, floor(2 * hw + 0.5), 1, 214, 60, 60) end end for y = 50, 52 do local dy = (y + 0.5 - 51) / 1.9 local hw = 9 * sqrt(max(0, 1 - dy * dy)) rect(floor(48.5 - hw + 0.5), y, floor(2 * hw + 0.5), 1, 214, 150, 84) end rect(44, 50, 2, 1, 250, 238, 206); rect(49, 51, 2, 1, 250, 238, 206); rect(52, 50, 1, 1, 250, 238, 206) px(47, 51, 96, 170, 70); px(51, 50, 96, 170, 70) rect(9, 57, 12, 3, 236, 236, 242) rect(8, 56, 14, 1, 236, 236, 242) rect(10, 56, 10, 1, 60, 34, 28) rect(6, 55, 4, 2, 250, 170, 170) rect(21, 55, 3, 2, 126, 190, 80) rect(8, 60, 14, 1, 160, 102, 66) BG = snapshot(0, 0, W, H) end local L, CYC, PICK, SP = 112, 360, 150, 28 local V = 84 / CYC local SPD = { 0.5, 0.75, 1, 1.3, 1.7 } local X0 = 7 local START = 60 local ST = {} for i = 1, 3 do local h = hash32(i * 0x9E3779B1) ST[i] = { life = 130 + umod(h, 40), off = umod(h >> 6, 200), sx = umod(h >> 12, 7) - 3, w = 4 + umod(h >> 20, 3) } end local function band(x0, wi, y, a) blend_rect(x0, y, wi, 1, MIST[1], MIST[2], MIST[3], a) blend(x0 - 1, y, MIST[1], MIST[2], MIST[3], a * 0.5) blend(x0 + wi, y, MIST[1], MIST[2], MIST[3], a * 0.5) end local function steam(p, T) local u = ((T + p.off) % p.life) / p.life local a = 0.34 * min(1, u * 4) * (1 - u) local y = 48 - u * 15 local x = 48 + p.sx + u * 4 + 1.5 * sin(u * 5 + p.off) local w = p.w + u * 5 local iy = floor(y) local fy = y - iy for k = 0, 2 do local ww = w * (k == 1 and 1 or 0.65) local x0, wi = floor(x - ww / 2 + 0.5), floor(ww + 0.5) band(x0, wi, iy + k, a * (1 - fy)) band(x0, wi, iy + k + 1, a * fy) end end local function taken(i, u, c) for cc = max(0, c - 1), c do if cc % 4 == i then local up = X0 + 28 * i + V * (cc * CYC + PICK) if floor(up / L) == floor(u / L) and u >= up then return true end end end return false end local function stick(tx, ty, slope) for y = 0, ty do local x = tx + slope * (ty - y) local ix = floor(x) local f = x - ix local r, g, b = 246, 222, 170 if ty - y < 3 then r, g, b = 80, 50, 40 end blend(ix, y, r, g, b, 1 - f) blend(ix + 1, y, r, g, b, f) end end function render() if not BG then bake() end blit_rgb(BG, 0, 0, W, H) local T = frame * SPD[cfg.speed or 3] + START local o = (T * V) % 8 for k = -1, 8 do local x = k * 8 + o local ix = floor(x) local f = x - ix blend_rect(ix, 24, 1, 15, 88, 54, 40, 0.55 * (1 - f)) blend_rect(ix + 1, 24, 1, 15, 88, 54, 40, 0.55 * f) end local c = floor(T / CYC) local p = T - c * CYC local grab = cfg.grab ~= false for i = 0, 3 do local u = X0 + 28 * i + V * T local n = floor(u / L) local xs = u - n * L - 20 if xs < W and not (grab and taken(i, u, c)) then put_plate((i + n) % 4 + 1, xs, 27) end end if grab and p > 30 and p < 250 then local i = c % 4 local u = X0 + 28 * i + V * T local n = floor(u / L) local xs = u - n * L - 20 local s = min(1, (p - 30) / 120) s = s * s * (3 - 2 * s) local py = 0 if p >= PICK + 10 then local q = (p - PICK - 10) / 80 py = -q * q * 50 end local top = p >= PICK and 28 + py or -8 + 36 * s local tx = xs + 9.5 + 0.8 * sin(p * 0.05) if p >= PICK then put_plate((i + n) % 4 + 1, xs, 27 + py) end local gap = p < PICK and 3 or max(1, 3 - (p - PICK) * 0.3) stick(tx, floor(top), 0.35) stick(tx + gap, floor(top), 0.5) end for i = 1, 3 do steam(ST[i], T) end end