info = { type = "image", title = "Torchlit castle hall", category = "city", author = "BRRRO", version = "1.0", license = "MIT", desc = "Camera drifts down a castle hall of torches", api = 33, } local tr = ({ sk = { ["Flame"] = "Plameň", ["Blue"] = "Modrý", ["Green"] = "Zelený", ["Orange"] = "Oranžový", ["Drift speed"] = "Rýchlosť posunu" }, cs = { ["Flame"] = "Plamen", ["Blue"] = "Modrý", ["Green"] = "Zelený", ["Orange"] = "Oranžový", ["Drift speed"] = "Rychlost posunu" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "flame", label = T("Flame"), type = "int", default = "blue", opts = { keys = { "blue", "green", "orange" }, T("Blue"), T("Green"), T("Orange") } }, { key = "speed", label = T("Drift speed"), type = "int", min = 1, max = 5, default = 3 }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local blit_rgb, snapshot, clip = gfx.blit_rgb, gfx.snapshot, gfx.clip local floor, sin, sqrt, max, min = math.floor, math.sin, math.sqrt, math.max, math.min local W, H = gfx.W, gfx.H local FLAMES = { blue = { { 60, 130, 255 }, { 20, 100, 230 }, { 60, 180, 255 }, { 190, 240, 255 } }, green = { { 70, 255, 110 }, { 20, 150, 60 }, { 90, 230, 110 }, { 210, 255, 200 } }, orange = { { 255, 150, 50 }, { 200, 60, 10 }, { 255, 140, 30 }, { 255, 230, 120 } }, } local PER = 208 local TORCHES = { 20, 96, 158 } local DOORS, WINDOWS = { 56 }, { 124, 186 } local BG local WALL = { { 62, 70, 98 }, { 56, 64, 92 } } local function bake() rect(0, 0, W, 4, 14, 16, 30); rect(0, 4, W, 4, 24, 26, 44) for k = 0, 3 do local c = WALL[k % 2 + 1] rect(0, 8 + 10 * k, W, 10, c[1], c[2], c[3]) rect(0, 8 + 10 * k, W, 1, 76, 86, 118) rect(0, 17 + 10 * k, W, 1, 44, 50, 76) end blend_rect(0, 8, W, 6, 0, 0, 12, 0.3) rect(0, 48, W, 4, 40, 44, 68); rect(0, 48, W, 1, 84, 92, 124) rect(0, 52, W, H - 52, 44, 46, 70); rect(0, 52, W, 1, 74, 80, 108) rect(0, 57, W, 1, 32, 34, 54); rect(0, 61, W, 1, 32, 34, 54) BG = snapshot(0, 0, W, H) end local function frect(x, y, w, h, r, g, b) local x0, x1 = floor(x), floor(x + w) if x0 >= W or x1 < 0 then return end if x1 == x0 then blend_rect(x0, y, 1, h, r, g, b, w) return end local fl, fr = x - x0, x + w - x1 local a = x0 if fl > 0 then blend_rect(x0, y, 1, h, r, g, b, 1 - fl); a = x0 + 1 end if x1 - 1 >= a then rect(a, y, x1 - a, h, r, g, b) end if fr > 0 then blend_rect(x1, y, 1, h, r, g, b, fr) end end local function wrap(v, p, margin) local s = v % p return s > p - margin and s - p or s end local function door(sx) frect(sx - 9, 16, 18, 32, 98, 106, 140) frect(sx - 7, 20, 14, 28, 96, 62, 40) frect(sx - 5, 18, 10, 2, 96, 62, 40) for k = -4, 4, 4 do frect(sx + k, 18, 1, 30, 72, 46, 32) end frect(sx - 7, 26, 14, 2, 40, 40, 54); frect(sx - 7, 38, 14, 2, 40, 40, 54) frect(sx + 3, 33, 2, 2, 204, 164, 64) frect(sx - 10, 47, 20, 1, 40, 44, 68) end local function window(sx) frect(sx - 6, 15, 12, 18, 104, 112, 146); frect(sx - 4, 14, 8, 1, 104, 112, 146) frect(sx - 5, 16, 10, 16, 20, 32, 74); frect(sx - 3, 15, 6, 1, 20, 32, 74) frect(sx - 5, 24, 10, 8, 28, 44, 96) px(floor(sx - 3), 19, 220, 230, 255); px(floor(sx + 2), 22, 180, 196, 240) frect(sx, 15, 1, 17, 52, 56, 80); frect(sx - 5, 22, 10, 1, 52, 56, 80) frect(sx - 7, 32, 14, 2, 132, 140, 170); frect(sx - 7, 34, 14, 1, 44, 50, 76) end local GLOW_R = { 8, 12, 16, 20 } local function glow(sx, F, t, ph) local fl = 1 + 0.12 * sin(t * 0.31 + ph) + 0.06 * sin(t * 0.77 + ph * 2) clip(0, 8, W, 40) for i = 1, 4 do local R = GLOW_R[i] * fl for dy = -R, R, 2 do local hw = floor(sqrt(max(0, R * R - dy * dy)) * 1.1 + 0.5) blend_rect(floor(sx) - hw, 22 + floor(dy), 2 * hw + 1, 2, F[1][1], F[1][2], F[1][3], 0.085) end end clip() end local function torch(sx, F, t, ph) frect(sx - 1, 30, 3, 6, 36, 34, 44) frect(sx - 3, 35, 7, 2, 36, 34, 44) frect(sx - 4, 26, 9, 1, 118, 120, 140) frect(sx - 3, 27, 7, 1, 40, 38, 50); frect(sx - 2, 28, 5, 1, 30, 28, 38) local cx = floor(sx + 0.5) local hf = 10 + floor(1.5 + 1.5 * sin(t * 0.37 + ph) + 0.5 * sin(t * 1.1 + ph)) for k = 0, hf - 1 do local u = k / hf local w = max(1, floor(6 * (1 - u ^ 1.5) + 0.5)) local off = floor(1.6 * sin(t * 0.23 + ph + k * 0.45) * u ^ 1.3 + 0.5) local x0 = cx - w // 2 + off rect(x0, 25 - k, w, 1, F[2][1], F[2][2], F[2][3]) if u < 0.7 then local wi = max(1, floor(w * 0.6)) rect(cx - wi // 2 + off, 25 - k, wi, 1, F[3][1], F[3][2], F[3][3]) if u < 0.4 then local wc = max(1, floor(w * 0.3)) rect(cx - wc // 2 + off, 25 - k, wc, 1, F[4][1], F[4][2], F[4][3]) end end end for e = 0, 2 do local u = (t * 0.35 + e * 7 + ph * 3) % 20 px(cx + floor(2.5 * sin(u * 0.5 + e * 2)), 24 - floor(u), F[3][1], F[3][2], F[3][3]) end end local function pillar(sx) frect(sx, 0, 8, H, 16, 18, 32) frect(sx, 0, 1, H, 44, 52, 84) frect(sx - 1, 0, 10, 3, 30, 32, 54); frect(sx - 1, 58, 10, 6, 30, 32, 54) end function render() if not BG then bake() return end blit_rgb(BG, 0, 0, W, H) local F = FLAMES[cfg.flame] or FLAMES.blue local v = 0.5 * (cfg.speed or 3) / 3 local cam, camf, camp = (frame * v) % PER, (frame * v * 1.3) % 20, (frame * v * 1.6) % 130 for k = 0, 3 do local c = WALL[k % 2 + 1] local a = (cam - 8 * (k % 2)) % 16 for j = -a, W, 16 do frect(j, 9 + 10 * k, 1, 8, 44, 50, 76) end end for j = -((cam * 0.5) % 52), W, 52 do frect(j, 0, 6, 8, 40, 32, 48) end for _, wx in ipairs(DOORS) do local s = wrap(wx - cam, PER, 24); if s > -12 and s < W + 12 then door(s) end end for _, wx in ipairs(WINDOWS) do local s = wrap(wx - cam, PER, 24); if s > -10 and s < W + 10 then window(s) end end for i, wx in ipairs(TORCHES) do local s = wrap(wx - cam, PER, 24) if s > -24 and s < W + 24 then glow(s, F, frame, i * 2.1) end end for i, wx in ipairs(TORCHES) do local s = wrap(wx - cam, PER, 24) if s > -8 and s < W + 8 then torch(s, F, frame, i * 2.1) end end for j = -camf, W, 20 do frect(j, 53, 1, 4, 32, 34, 54) end for j = -((camf + 10) % 20), W, 20 do frect(j, 58, 1, 3, 32, 34, 54) end local p = wrap(60 - camp, 130, 12) if p > -10 and p < W then pillar(p) end end