info = { type = "image", title = "Backrooms hall", category = "city", author = "BRRRO", version = "1.0", license = "MIT", desc = "Walking down an endless yellow office corridor", api = 33, } local ltr = ({ sk = { ["Walking speed"] = "Rýchlosť chôdze", ["Wallpaper"] = "Tapeta", ["Flickering lights"] = "Blikajúce svetlá" }, cs = { ["Walking speed"] = "Rychlost chůze", ["Wallpaper"] = "Tapeta", ["Flickering lights"] = "Blikající světla" }, })[lang] or {} local function LT(s) return ltr[s] or s end settings = { { key = "speed", label = LT("Walking speed"), type = "int", min = 1, max = 5, default = 3 }, { key = "tone", label = LT("Wallpaper"), type = "color", default = "#E8C834" }, { key = "flick", label = LT("Flickering lights"), type = "bool", default = true }, } local rect, blend_rect = gfx.rect, gfx.blend_rect local floor, abs, max, min = math.floor, math.abs, math.max, math.min local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local CX, CY = 32, 30 local A, B1, B2 = 34, 20, 30 local P = 4 local ZN, ZD, ZE = 0.75, 8, 9 local function mix(c, d, t) return { floor(c[1] + (d[1] - c[1]) * t + 0.5), floor(c[2] + (d[2] - c[2]) * t + 0.5), floor(c[3] + (d[3] - c[3]) * t + 0.5) } end local function sc(c, f) return { floor(c[1] * f + 0.5), floor(c[2] * f + 0.5), floor(c[3] * f + 0.5) } end local FOG = { 240, 226, 150 } local function mkpal(tone, f) local p = { wl = {}, wr = {} } for i = 1, 4 do local m = mix(tone, FOG, (i - 1) * 0.2) p.wl[i], p.wr[i] = sc(m, f), sc(m, f * 0.86) end p.fog = sc(FOG, f) p.cl = { sc({ 248, 238, 192 }, f), sc({ 244, 232, 178 }, f), sc({ 240, 226, 164 }, f) } p.fl = { sc({ 184, 144, 74 }, f), sc({ 198, 160, 90 }, f), sc({ 212, 176, 108 }, f) } p.base = sc({ 132, 92, 28 }, f) p.seamc = sc({ 220, 204, 142 }, f) p.seamf = sc({ 140, 102, 40 }, f) p.lamp = sc({ 255, 253, 228 }, f) p.flk = sc({ 255, 253, 228 }, f * 0.9) p.off = sc({ 210, 190, 112 }, f) p.strl = sc(mix(tone, { 150, 100, 20 }, 0.35), f) p.far = sc(mix(tone, { 120, 80, 10 }, 0.30), f) p.frame = sc({ 124, 84, 26 }, f) p.door = sc({ 198, 142, 54 }, f) p.knob = sc({ 255, 238, 150 }, f) return p end local PALS, BG = nil, {} local V = 0.095 local FLICK = true function on_settings() local t = cfg.tone or { r = 232, g = 200, b = 52 } local tone = { t.r, t.g, t.b } PALS = { mkpal(tone, 1), mkpal(tone, 0.95) } BG = {} V = 0.035 + 0.01 * (cfg.speed or 3) FLICK = cfg.flick ~= false end local function dxof(x) return x < CX and (CX - 0.5 - x) or (x + 0.5 - CX) end local function build_bg(p) for x = 0, W - 1 do local dx = dxof(x) local k = dx / A local yt = floor(CY - B1 * k + 0.5) local yb = floor(CY + B2 * k + 0.5) local band = dx > 20 and 1 or (dx > 10 and 2 or (dx > 5 and 3 or 4)) local left = x < CX local wc = left and p.wl[band] or p.wr[band] if dx < A / ZE then wc = p.fog end local c = p.cl[1] rect(x, 0, 1, min(yt, 8), c[1], c[2], c[3]) if yt > 8 then c = p.cl[2]; rect(x, 8, 1, min(yt, 18) - 8, c[1], c[2], c[3]) end if yt > 18 then c = p.cl[3]; rect(x, 18, 1, yt - 18, c[1], c[2], c[3]) end if yb < 42 then c = p.fl[3]; rect(x, yb, 1, 42 - yb, c[1], c[2], c[3]) end if yb < 52 then c = p.fl[2]; rect(x, max(yb, 42), 1, 52 - max(yb, 42), c[1], c[2], c[3]) end c = p.fl[1]; rect(x, max(yb, 52), 1, H - max(yb, 52), c[1], c[2], c[3]) rect(x, yt, 1, yb - yt, wc[1], wc[2], wc[3]) if dx >= A / ZE and yb - yt > 4 then local bh = dx > 14 and 2 or 1 rect(x, yb - bh, 1, bh, p.base[1], p.base[2], p.base[3]) end end end local function fill(x, y, h, c, cov) if h <= 0 then return end if cov >= 0.97 then rect(x, y, 1, h, c[1], c[2], c[3]) elseif cov > 0.04 then blend_rect(x, y, 1, h, c[1], c[2], c[3], cov) end end local function wall_seg(left, z1, z2, ya, yb, c, cut) cut = cut or ZD if z2 <= ZN or z1 >= cut then return end if z1 < ZN then z1 = ZN end if z2 > cut then z2 = cut end local d1, d2 = A / z1, A / z2 local xs, xe if left then xs, xe = floor(CX - d1), floor(CX - d2) else xs, xe = floor(CX + d2), floor(CX + d1) end for x = max(xs, 0), min(xe, W - 1) do local lo, hi if left then lo, hi = CX - x - 1, CX - x else lo, hi = x - CX, x + 1 - CX end local cov = min(hi, d1) - max(lo, d2) if cov > 0.04 then local k = dxof(x) / A local y0 = floor(CY + ya * k + 0.5) fill(x, y0, floor(CY + yb * k + 0.5) - y0, c, cov) end end end local function side_opening(left, z1, z2, p) if z2 <= ZN or z1 >= ZD then return end if z1 < ZN then z1 = ZN end if z2 > ZD then z2 = ZD end local d1, d2 = A / z1, A / z2 local xs, xe if left then xs, xe = floor(CX - d1), floor(CX - d2) else xs, xe = floor(CX + d2), floor(CX + d1) end local ft = CY - B1 / z2 local fb = CY + B2 / z2 local rt, rb = floor(ft), floor(fb) local cc, fc, wc = p.cl[2], p.fl[2], p.far for x = max(xs, 0), min(xe, W - 1) do local lo, hi if left then lo, hi = CX - x - 1, CX - x else lo, hi = x - CX, x + 1 - CX end local cov = min(hi, d1) - max(lo, d2) if cov > 0.04 then local k = dxof(x) / A local yt = floor(CY - B1 * k + 0.5) local yb = floor(CY + B2 * k + 0.5) fill(x, yt, rt + 1 - yt, cc, cov) fill(x, rt, 1, wc, cov * (rt + 1 - ft)) fill(x, rt + 1, rb - rt - 1, wc, cov) fill(x, rb, 1, fc, cov) fill(x, rb, 1, wc, cov * (fb - rb)) fill(x, rb + 1, yb - rb - 1, fc, cov) end end end local function hband(ya, yb, c, hwk) if yb <= ya then return end for y = max(floor(ya), 0), min(floor(yb), H - 1) do local cov = min(y + 1, yb) - max(y, ya) if cov > 0.04 then local hw = hwk * abs(y + 0.5 - CY) local x0 = max(floor(CX - hw + 0.5), 0) local x1 = min(floor(CX + hw + 0.5), W) if x1 > x0 then if cov >= 0.97 then rect(x0, y, x1 - x0, 1, c[1], c[2], c[3]) else blend_rect(x0, y, x1 - x0, 1, c[1], c[2], c[3], cov) end end end end end local function ctype(n, side) local m = n % 8 if side == 0 then return m == 3 and 2 or (m == 5 and 1 or 0) end return m == 7 and 2 or ((m == 0 or m == 2) and 1 or 0) end local function door(left, z1, z2, p) local top = -B1 * 0.38 wall_seg(left, z1, z2, top - 2.5, top, p.frame) wall_seg(left, z1, z2, top, B2, p.frame) wall_seg(left, z1 + 0.1, z2 - 0.1, top, B2, p.door) local zk = z1 + 0.22 if zk > ZN and zk < 5 then local fx = left and (CX - A / zk) or (CX + A / zk) local xa = floor(fx - 0.5) local f = fx - 0.5 - xa local y = floor(CY + 8 * (A / zk) / A + 0.5) local kc = p.knob if xa >= 0 and xa < W then blend_rect(xa, y, 1, 1, kc[1], kc[2], kc[3], 1 - f) end if xa + 1 >= 0 and xa + 1 < W then blend_rect(xa + 1, y, 1, 1, kc[1], kc[2], kc[3], f) end end end function render() if not PALS then return end local t = frame * STEP_HZ // FPS local T = t * V local nb = floor(T / P) local ph = T - nb * P local pi = 1 if FLICK then local r = (t + 37) % 190 if r == 0 or r == 1 or r == 3 or r == 6 or r == 7 then pi = 2 end end local p = PALS[pi] if not BG[pi] then build_bg(p) BG[pi] = gfx.snapshot(0, 0, W, H) else gfx.blit_rgb(BG[pi], 0, 0, W, H) end for k = 0, 3 do local n = nb + k local z0 = k * P - ph for s = 0, 2, 2 do local z = z0 + s if z > 0.8 and z < 10 then local y = CY - B1 / z hband(y - 0.5, y + 0.5, p.seamc, A / B1) y = CY + B2 / z hband(y - 0.5, y + 0.5, p.seamf, A / B2) end end local zn, zf = z0 + 1.2, z0 + 2.7 if zf > ZN and zn < 10 then local lc = p.lamp if n % 11 == 4 then lc = p.off elseif FLICK and (t + n * 13) % 97 < 2 then lc = p.flk end hband(CY - B1 / max(zn, ZN), CY - B1 / min(zf, 14), lc, 0.612) end for side = 0, 1 do local left = side == 0 local ty = ctype(n, side) if ty == 0 then wall_seg(left, z0, z0 + 0.1, -B1, B2 - 2, p.strl) wall_seg(left, z0 + 2, z0 + 2.1, -B1, B2 - 2, p.strl) elseif ty == 1 then door(left, z0 + 1.3, z0 + 2.5, p) else side_opening(left, z0 + 0.9, z0 + 3.1, p) end end end end