info = { type = "image", title = "Backrooms elevator", category = "city", author = "BRRRO", version = "1.0", license = "MIT", desc = "Elevator doors open onto yellow rooms", api = 33, } local tr = ({ sk = { ["Doors open (s)"] = "Otvorené dvere (s)", ["Display colour"] = "Farba displeja" }, cs = { ["Doors open (s)"] = "Otevřené dveře (s)", ["Display colour"] = "Barva displeje" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "hold", label = T("Doors open (s)"), type = "int", min = 1, max = 8, default = 3 }, { key = "digit", label = T("Display colour"), type = "color", default = "#FFA020" }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, ceil, sin, max, min = math.floor, math.ceil, math.sin, math.max, math.min local hash32, umod = math.hash32, math.umod local W, H = gfx.W, gfx.H local OX, OY, OW, OH = 12, 20, 40, 38 local STEEL, STEEL_HI, STEEL_SEAM, STEEL_KICK = { 164, 172, 186 }, { 196, 204, 216 }, { 130, 138, 152 }, { 118, 126, 140 } local FRAME = { 84, 94, 112 } local HAZ = { 252, 224, 30 } local DIG = { 255, 160, 32 } local DOPTS = { font = "6x10" } local DOPTS_C = { font = "6x10", w = 17, align = "center" } local LAMP_ON, LAMP_DEAD, LAMP_WARM = { 255, 253, 228 }, { 196, 190, 156 }, { 214, 190, 130 } local HOLD = 90 local MV, DO, DC = 90, 30, 30 local CYC = MV + DO + HOLD + DC local DTOP = 0 function on_settings() local c = cfg.digit or { r = 255, g = 160, b = 32 } DIG = { c.r, c.g, c.b } HOLD = (cfg.hold or 3) * 30 CYC = MV + DO + HOLD + DC end local BG = nil local function build_bg() rect(0, 0, W, H, 224, 198, 90) for x = 3, W - 1, 8 do rect(x, 0, 1, 58, 204, 176, 62) end rect(0, 58, W, 6, 196, 158, 88) rect(0, 58, W, 1, 132, 92, 28) rect(0, 61, W, 1, 176, 138, 70) rect(9, 17, 46, 42, FRAME[1], FRAME[2], FRAME[3]) rect(10, 18, 44, 1, 120, 132, 152) rect(12, 20, OW, OH, 0, 0, 0) rect(17, 2, 30, 13, FRAME[1], FRAME[2], FRAME[3]) rect(18, 3, 28, 11, 0, 0, 0) rect(56, 32, 6, 14, FRAME[1], FRAME[2], FRAME[3]) rect(57, 33, 4, 12, STEEL[1], STEEL[2], STEEL[3]) rect(58, 35, 2, 1, 40, 40, 50); rect(57, 36, 4, 1, 40, 40, 50) rect(57, 41, 4, 1, 40, 40, 50); rect(58, 42, 2, 1, 40, 40, 50) rect(56, 26, 6, 6, FRAME[1], FRAME[2], FRAME[3]) rect(57, 27, 4, 4, 30, 24, 10) BG = gfx.snapshot(0, 0, W, H) end local ROOMS = { { wl = { 232, 204, 60 }, wr = { 212, 184, 48 }, ew = { 240, 216, 90 }, ce = { 248, 238, 192 }, fl = { 200, 162, 90 } }, { wl = { 236, 172, 50 }, wr = { 212, 148, 36 }, ew = { 244, 192, 80 }, ce = { 248, 226, 170 }, fl = { 190, 140, 70 } }, { wl = { 222, 208, 130 }, wr = { 200, 186, 108 }, ew = { 232, 220, 150 }, ce = { 250, 244, 210 }, fl = { 186, 160, 100 } }, } local SNAP = {} local RA, RB1, RB2, RCX, RCY = 22, 16, 18, 32, 38 local function build_room(v) local r = ROOMS[v] for x = OX, OX + OW - 1 do local dx = x < RCX and (RCX - 0.5 - x) or (x + 0.5 - RCX) local k = dx / RA local yt = floor(RCY - RB1 * k + 0.5) local yb = floor(RCY + RB2 * k + 0.5) local isend = dx < 11 if isend then yt, yb = 30, 48 end yt = max(yt, OY); yb = min(yb, OY + OH) rect(x, OY, 1, yt - OY, r.ce[1], r.ce[2], r.ce[3]) local c = isend and r.ew or (x < RCX and r.wl or r.wr) rect(x, yt, 1, yb - yt, c[1], c[2], c[3]) rect(x, yb, 1, OY + OH - yb, r.fl[1], r.fl[2], r.fl[3]) if not isend and yb - yt > 3 then rect(x, yb - 2, 1, 2, 132, 92, 28) end end rect(21, 46, 22, 2, 132, 92, 28) if v == 1 then rect(34, 33, 7, 15, 124, 84, 26); rect(35, 34, 5, 14, 198, 142, 54) elseif v == 2 then rect(24, 32, 8, 16, 120, 100, 50); rect(25, 33, 6, 15, 60, 44, 14) rect(37, 36, 3, 6, 18, 12, 4); rect(38, 34, 1, 2, 18, 12, 4) rect(37, 42, 1, 6, 18, 12, 4); rect(39, 42, 1, 6, 18, 12, 4) else rect(24, 32, 8, 16, 120, 82, 24); rect(25, 33, 6, 15, 70, 50, 14) end rect(OX, 52, OW, 1, 152, 114, 46); rect(OX, 56, OW, 1, 146, 108, 42) SNAP[v] = gfx.snapshot(OX, OY, OW, OH) end local function room(v, t) if not SNAP[v] then build_room(v) else gfx.blit_rgb(SNAP[v], OX, OY, OW, OH) end local r = ROOMS[v] local lc = LAMP_ON if v == 3 and (t // 4) % 9 == 0 then lc = LAMP_DEAD end if v == 2 and umod(hash32((t // 3) * 977), 11) == 0 then lc = LAMP_WARM end for y = 22, 25 do local dx = 0.55 * (RCY - y - 0.5) rect(floor(RCX - dx + 0.5), y, floor(2 * dx + 0.5), 1, lc[1], lc[2], lc[3]) end end local function dashes(x, w, a) if a >= 1 then rect(x, OY, w, OH, 0, 0, 0) for y = OY, OY + OH - 2, 4 do rect(x, y, w, 2, HAZ[1], HAZ[2], HAZ[3]) end else blend_rect(x, OY, w, OH, 0, 0, 0, a) for y = OY, OY + OH - 2, 4 do blend_rect(x, y, w, 2, HAZ[1], HAZ[2], HAZ[3], a) end end end local function leaf(x0, w, outer_left) rect(x0, OY, w, OH, STEEL[1], STEEL[2], STEEL[3]) local hx = outer_left and (x0 + 3) or (x0 + w - 5) rect(hx, OY, 2, OH - 4, STEEL_HI[1], STEEL_HI[2], STEEL_HI[3]) rect(outer_left and (x0 + 9) or (x0 + w - 10), OY, 1, OH - 4, STEEL_SEAM[1], STEEL_SEAM[2], STEEL_SEAM[3]) rect(x0, OY + OH - 4, w, 4, STEEL_KICK[1], STEEL_KICK[2], STEEL_KICK[3]) px(x0 + (outer_left and 6 or w - 7), OY + 4, 100, 108, 122) end local function leaves(o) if o >= 20 then return end gfx.clip(OX, OY, OW, OH) local edge = 32 - o local E = floor(edge) local fr = edge - E leaf(E - 20, 20, true) dashes(E - 2, 2, 1) if fr > 0.04 then dashes(E, 1, fr) end local s = 32 + o local E2 = ceil(s) leaf(E2, 20, false) dashes(E2, 2, 1) if E2 - s > 0.04 then dashes(E2 - 1, 1, E2 - s) end gfx.clip() end local function chevron(cx, y, r, g, b) rect(cx, y, 1, 1, r, g, b) rect(cx - 1, y + 1, 3, 1, r, g, b) rect(cx - 2, y + 2, 5, 1, r, g, b) end local function display(num, moving, on, t) if not on then return end local r, g, b = DIG[1], DIG[2], DIG[3] gfx.clip(19, 4, 7, 9) if moving then local o = (t // 2) % 4 for i = 0, 2 do chevron(22, 4 + i * 4 - o, r, g, b) end else rect(22, 5, 1, 1, r, g, b); rect(21, 6, 3, 1, r, g, b); rect(20, 7, 5, 1, r, g, b) rect(19, 8, 7, 1, r, g, b); rect(22, 9, 1, 3, r, g, b) end gfx.clip() local s = tostring(num) gfx.text(28, DTOP, s, r, g, b, DOPTS_C) end local STEP_HZ = 30 function render() if not BG then build_bg() local top = gfx.text_ink("8", DOPTS) DTOP = 3 + (11 - 10) // 2 - top + 1 else gfx.blit_rgb(BG, 0, 0, W, H) end local fr = frame * STEP_HZ // gfx.FPS local t = fr % CYC local cyc = fr // CYC local n0 = (3 * cyc) % 10 local o = 0 local moving, num, on = false, 0, true if t < MV then moving = true num = (n0 + min(3, t // 22)) % 10 if t % 22 == 0 and t > 0 then on = false end elseif t < MV + DO then local u = (t - MV) / DO o = 20 * u * u * (3 - 2 * u) num = (n0 + 3) % 10 local a = t - MV on = not (a < 3 or (a >= 6 and a < 9)) elseif t < MV + DO + HOLD then o = 20 num = (n0 + 3) % 10 else local u = (t - MV - DO - HOLD) / DC o = 20 * (1 - u * u * (3 - 2 * u)) num = (n0 + 3) % 10 end if o > 0.05 then room(cyc % 3 + 1, t) blend_rect(14, 59, 36, 4, 255, 236, 140, 0.3) end leaves(o) display(num, moving, on, t) local lr, lg, lb if moving then if (t // 6) % 2 == 0 then lr, lg, lb = 255, 170, 20 else lr, lg, lb = 100, 60, 8 end else lr, lg, lb = 60, 235, 90 end rect(58, 28, 2, 2, lr, lg, lb) end