info = { type = "image", title = "Lantern night market", category = "city", author = "BRRRO", version = "1.0", license = "MIT", desc = "Camera glides along night market stalls", api = 44, } local tr = ({ sk = { ["Lanterns"] = "Lampióny", ["red"] = "červené", ["warm white"] = "teplé biele" }, cs = { ["Lanterns"] = "Lampiony", ["red"] = "červené", ["warm white"] = "teplé bílé" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "lamp", label = T("Lanterns"), type = "int", default = "red", opts = { keys = { "red", "warm" }, T("red"), T("warm white") } }, } local rect, px, blend_rect, blit_rgb, clip, snapshot = gfx.rect, gfx.px, gfx.blend_rect, gfx.blit_rgb, gfx.clip, gfx.snapshot local floor, sin, sqrt, min = math.floor, math.sin, math.sqrt, math.min local hash32, umod = math.hash32, math.umod local KR, KG, KB = 255, 0, 255 local LAMPS = { red = { body = { 214, 44, 34 }, hi = { 255, 118, 72 }, glow = { 255, 90, 52 }, dim = { 160, 36, 32 } }, warm = { body = { 255, 224, 166 }, hi = { 255, 250, 226 }, glow = { 255, 196, 120 }, dim = { 196, 162, 112 } }, } local L local STALL_X = { 8, 72, 136 } local AWN = { { { 156, 44, 48 }, { 214, 194, 166 } }, { { 40, 112, 78 }, { 214, 194, 166 } }, { { 190, 118, 44 }, { 130, 66, 40 } }, } local NLANT = 24 local function lx(i) return 4 + 8 * i end local function string_y(wx) return 11 + floor(3 * sin(3.14159 * (wx % 64) / 64) + 0.5) end local MID, FAR, stage = {}, {}, 0 local function lerp(a, b, t) return a + (b - a) * t end local function glow(cx, cy, r, a) for dy = -r, r do local hw = floor(sqrt(r * r + 0.6 - dy * dy) + 0.5) blend_rect(cx - hw, cy + dy, 2 * hw + 1, 1, L.glow[1], L.glow[2], L.glow[3], a) end end local function stall(k, ox) local X = STALL_X[k] - ox if X > 66 or X < -54 then return end local A, B = AWN[k][1], AWN[k][2] rect(X, 24, 50, 22, 42, 28, 46) for i = 0, 17 do local c = (i % 2 == 0) and A or B rect(X - 2 + i * 3, 17, 3, 7, c[1], c[2], c[3]) if i % 2 == 0 then rect(X - 2 + i * 3, 24, 3, 1, c[1], c[2], c[3]) end end blend_rect(X, 25, 50, 2, 0, 0, 0, 0.4) rect(X - 1, 25, 2, 27, 70, 48, 34) rect(X + 49, 25, 2, 27, 70, 48, 34) rect(X - 1, 44, 52, 2, 156, 108, 66) rect(X - 1, 46, 52, 6, 88, 58, 42) for i = 1, 3 do rect(X - 1 + i * 13, 46, 1, 6, 62, 40, 32) end if k == 1 then rect(X + 13, 38, 9, 6, 150, 152, 162) rect(X + 12, 37, 11, 1, 196, 198, 206) rect(X + 14, 38, 7, 1, 240, 200, 120) rect(X + 28, 42, 6, 2, 236, 226, 206); rect(X + 29, 40, 5, 2, 236, 226, 206) rect(X + 4, 28, 12, 8, 98, 50, 40) for i = 0, 4 do px(X + 6 + i * 2, 30 + (i % 2) * 2, 244, 214, 150); px(X + 6 + i * 2, 33, 244, 214, 150) end rect(X + 35, 34, 9, 10, 20, 14, 26) rect(X + 37, 29, 5, 5, 20, 14, 26) rect(X + 36, 26, 7, 3, 238, 234, 228); rect(X + 37, 24, 5, 2, 238, 234, 228) elseif k == 2 then local fr = { { 232, 124, 36 }, { 206, 44, 48 }, { 122, 176, 56 } } for i = 0, 2 do rect(X + 3 + 14 * i, 41, 12, 3, 124, 86, 52) for j = 0, 5 do local c = fr[(i + j) % 3 + 1] rect(X + 4 + 14 * i + 2 * j, 39 + j % 2, 2, 2, c[1], c[2], c[3]) end end for i = 0, 3 do rect(X + 8 + 9 * i, 25, 1, 3, 90, 60, 40); rect(X + 7 + 9 * i, 28, 3, 4, 234, 208, 62) end rect(X + 39, 37, 6, 7, 20, 14, 26); rect(X + 40, 33, 4, 4, 20, 14, 26); rect(X + 37, 31, 8, 2, 192, 162, 92) else local cs = { L.body, { 214, 170, 52 }, { 70, 150, 110 }, L.body, { 214, 170, 52 }, { 70, 150, 110 } } for i = 0, 5 do local c = cs[i + 1] local x, y = X + 5 + 7 * i, 27 + (i % 2) * 5 rect(x + 1, y - 2, 1, 2, 90, 60, 40) rect(x, y, 3, 4, c[1], c[2], c[3]) px(x + 1, y + 1, 255, 236, 190) end rect(X + 36, 41, 7, 4, 12, 10, 18); rect(X + 41, 38, 4, 3, 12, 10, 18) px(X + 41, 37, 12, 10, 18); px(X + 44, 37, 12, 10, 18) px(X + 42, 39, 255, 226, 90); px(X + 44, 39, 255, 226, 90) rect(X + 8, 42, 8, 2, 226, 214, 190); rect(X + 17, 40, 4, 4, 196, 90, 70) end clip(X - 1, 17, 52, 35) for i = 0, NLANT - 1 do local wx = lx(i) + 0 local d = wx - ox - (X + 25) if d > -34 and d < 34 then glow(wx - ox, string_y(wx) + 6, 9, 0.11) end end clip() end local function mid_tile(ox) rect(0, 0, 64, 64, KR, KG, KB) for y = 52, 63 do local t = (y - 52) / 11 rect(0, y, 64, 1, floor(lerp(44, 34, t)), floor(lerp(36, 28, t)), floor(lerp(52, 42, t))) end for i = 1, 36 do local h = hash32(i * 0x85EBCA6B + ox) rect(umod(h, 64), 53 + umod(h >> 8, 10), 2, 1, 58, 48, 66) end for k = 1, 3 do stall(k, ox) end for j = 0, 3 do local x = 64 * j - ox if x > -3 and x < 66 then rect(x - 1, 8, 3, 44, 66, 44, 34) end end for x = 0, 63 do local wx = x + ox if wx < 193 then rect(x, string_y(wx), 1, 1, 50, 36, 30) end end clip(0, 52, 64, 12) for i = 0, NLANT - 1 do local cx = lx(i) - ox if cx > -10 and cx < 74 then for r = 0, 4 do blend_rect(cx - 8 + r, 53 + r * 2, 17 - 2 * r, 2, L.glow[1], L.glow[2], L.glow[3], 0.07) end rect(cx, 55, 1, 2, L.glow[1] // 2, L.glow[2] // 2, L.glow[3] // 2) end end clip() end local function far_tile(ox) for y = 0, 39 do local t = y / 39 rect(0, y, 64, 1, floor(lerp(8, 34, t)), floor(lerp(10, 24, t)), floor(lerp(34, 66, t))) end rect(0, 40, 64, 24, 22, 16, 38) for i = 1, 22 do local h = hash32(i * 0x9E3779B1) local x = umod(h, 128) - ox if x >= 0 and x < 64 then px(x, 2 + umod(h >> 8, 22), 150, 156, 210) end end local mx = 92 - ox if mx > -6 and mx < 70 then rect(mx - 2, 8, 5, 5, 238, 232, 200); rect(mx - 1, 7, 3, 7, 238, 232, 200); rect(mx - 1, 8, 2, 5, 8, 10, 34) end local x = 0 local b = 0 while x < 128 do b = b + 1 local h = hash32(b * 0x85EBCA6B) local w, top = 6 + umod(h, 6), 40 - (10 + umod(h >> 8, 17)) local sx = x - ox if sx < 64 and sx + w > 0 then rect(sx, top, w, 24, 26, 20, 50) if umod(h >> 16, 3) == 0 then rect(sx + 1, top - 2, w - 2, 2, 26, 20, 50) end for wy = top + 2, 37, 3 do for wx = x + 1, x + w - 2, 3 do local hh = hash32(wx * 31 + wy * 7919) if umod(hh, 5) == 0 then px(wx - ox, wy, 255, 196, 110) elseif umod(hh, 11) == 0 then px(wx - ox, wy, 150, 112, 76) end end end end x = x + w end for j = 0, 17 do local fx = 3 + 7 * j - ox local fy = 31 + j % 3 if fx > -3 and fx < 66 then rect(fx, fy, 2, 2, L.dim[1], L.dim[2], L.dim[3]) px(fx, fy, L.hi[1], L.hi[2], L.hi[3]) end end end function on_settings() L = LAMPS[cfg.lamp] or LAMPS.red stage = 0 end local CAMP = { 0, 64, 128, 64, 0 } local HOLD, MOVE = 150, 80 local PER = HOLD + MOVE local function camera(t) t = t % (4 * PER) local k = t // PER local r = t - k * PER local a, b = CAMP[k + 1], CAMP[k + 2] if r < HOLD then return a end local u = (r - HOLD) / MOVE return a + (b - a) * (0.2 * u + 0.8 * u * u * (3 - 2 * u)) end local function sbar(x, y, w, h, r, g, b) local ix = floor(x) local f = x - ix rect(ix + 1, y, w - 1, h, r, g, b) blend_rect(ix, y, 1, h, r, g, b, 1 - f) blend_rect(ix + w, y, 1, h, r, g, b, f) end local function lantern(x, y) local c, h = L.body, L.hi rect(floor(x + 0.5), y - 2, 1, 2, 90, 60, 40) sbar(x - 1, y, 3, 1, 96, 66, 26) sbar(x - 2, y + 1, 5, 4, c[1], c[2], c[3]) sbar(x - 1, y + 5, 3, 1, c[1], c[2], c[3]) rect(floor(x + 0.5), y + 1, 1, 4, h[1], h[2], h[3]) rect(floor(x + 0.5), y + 6, 1, 2, 196, 150, 56) end local WALK = { { 20, 0.55, 1 }, { 70, -0.7, 2 }, { 120, 0.45, 3 }, { 170, -0.6, 4 }, { 200, 0.8, 1 }, } local PERIOD = 230 local function person(x, kind, ph) local a = ph % 2 == 0 and 0 or 1 if kind == 3 then sbar(x + 1, 53, 3, 3, 3, 3, 6) sbar(x, 56, 5, 4, 3, 3, 6) sbar(x + a, 60, 2, 4, 3, 3, 6); sbar(x + 3 - a, 60, 2, 4, 3, 3, 6) return end if kind == 2 then sbar(x - 1, 44, 8, 2, 3, 3, 6); sbar(x + 2, 43, 2, 1, 3, 3, 6) end sbar(x + 1, 46, 4, 4, 3, 3, 6) sbar(x, 50, 6, 8, 3, 3, 6) sbar(x + a, 58, 2, 6, 3, 3, 6); sbar(x + 4 - a, 58, 2, 6, 3, 3, 6) if kind == 4 then sbar(x + 7, 53, 3, 3, L.body[1], L.body[2], L.body[3]) px(floor(x + 8.5), 54, L.hi[1], L.hi[2], L.hi[3]) sbar(x + 5, 52, 3, 1, 3, 3, 6) end end local STEAM = 7 function render() if stage < 5 then stage = stage + 1 if stage <= 3 then mid_tile(64 * (stage - 1)) ; MID[stage] = snapshot(0, 0, 64, 64) else far_tile(64 * (stage - 4)); FAR[stage - 3] = snapshot(0, 0, 64, 64) end gfx.clear(0, 0, 0) gfx.ready(false) return end local cam = camera(frame) local cx = floor(cam + 0.5) local fx = floor(cam * 0.5 + 0.5) for k = 0, 1 do local x = 64 * k - fx if x > -64 and x < 64 then blit_rgb(FAR[k + 1], x, 0, 64, 64) end end for k = 0, 2 do local x = 64 * k - cx if x > -64 and x < 64 then blit_rgb(MID[k + 1], x, 0, 64, 64, KR, KG, KB) end end for i = 0, NLANT - 1 do local wx = lx(i) local sx = wx - cx if sx > -8 and sx < 72 then lantern(sx + 1.3 * sin(frame * 0.045 + i * 1.3), string_y(wx) + 2) end end local pxs = STALL_X[1] + 18 - cx if pxs > -6 and pxs < 70 then for i = 0, STEAM - 1 do local p = (frame * 0.35 + i * 9) % 63 local y = 36 - p * 0.42 local iy = floor(y) local f = y - iy local a = 0.45 * (1 - p / 63) local x = floor(pxs + 2.5 * sin(p * 0.13 + i * 1.9) + 0.5) blend_rect(x, iy, 2, 1, 236, 236, 244, a * (1 - f)) blend_rect(x, iy + 1, 2, 1, 236, 236, 244, a * f) end end for i = 1, #WALK do local w = WALK[i] local x = (w[1] + w[2] * frame - 1.3 * cam) % PERIOD - 30 if x > -12 and x < 70 then person(x, w[3], floor(frame / 6 + i)) end end end