info = { type = "image", title = "Tower lookup", category = "city", author = "BRRRO", version = "1.0", license = "MIT", desc = "Night skyscrapers seen from the street", api = 33, } local tr = ({ sk = { ["Lights"] = "Svetlá", ["Calm"] = "Pokojné", ["Normal"] = "Bežné", ["Busy"] = "Rušné", ["Plane"] = "Lietadlo" }, cs = { ["Lights"] = "Světla", ["Calm"] = "Klidná", ["Normal"] = "Běžná", ["Busy"] = "Rušná", ["Plane"] = "Letadlo" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "lights", label = T("Lights"), type = "int", default = 1, opts = { T("Calm"), T("Normal"), T("Busy") } }, { key = "plane", label = T("Plane"), type = "bool", default = true }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local floor, sin = math.floor, math.sin local hash32 = math.hash32 local W, H = gfx.W, gfx.H local VY = -6 local SKY0, SKY1 = { 10, 12, 52 }, { 74, 50, 124 } local FL, FL_D, FR, FR_D = { 46, 50, 108 }, { 22, 26, 66 }, { 38, 42, 92 }, { 18, 22, 58 } local FC, FC_D = { 62, 66, 128 }, { 30, 34, 84 } local RIM = { 94, 100, 172 } local LIT = { { 246, 212, 120 }, { 246, 212, 120 }, { 200, 226, 255 }, { 236, 150, 70 } } local function mix(a, b, t) return floor(a[1] + (b[1] - a[1]) * t + 0.5), floor(a[2] + (b[2] - a[2]) * t + 0.5), floor(a[3] + (b[3] - a[3]) * t + 0.5) end local function kf(y) return (y - VY) / (H - 1 - VY) end local BX, BY, BW, BH, BC, BP, BPH, NB = {}, {}, {}, {}, {}, {}, {}, 0 local function window(x, y, w, h, dark, seed) if x >= W or x + w <= 0 or h < 1 then return end local v = hash32(seed) local r = (v & 0xFF) % 100 local c = LIT[(v >> 8) % 4 + 1] if r < 50 then rect(x, y, w, h, dark[1], dark[2], dark[3]) elseif r < 85 then rect(x, y, w, h, c[1], c[2], c[3]) else rect(x, y, w, h, dark[1], dark[2], dark[3]) NB = NB + 1 BX[NB], BY[NB], BW[NB], BH[NB], BC[NB] = x, y, w, h, c BP[NB], BPH[NB] = 70 + (v >> 12) % 150, (v >> 20) % 200 end end local function tower(sgn, ue, ytop, fc, dark, seed) for y = ytop, H - 1 do local xe = floor(32 + sgn * ue * kf(y) + 0.5) if sgn < 0 then rect(0, y, xe, 1, fc[1], fc[2], fc[3]); px(xe - 1, y, RIM[1], RIM[2], RIM[3]) else rect(xe, y, W - xe, 1, fc[1], fc[2], fc[3]); px(xe, y, RIM[1], RIM[2], RIM[3]) end end local xr = floor(32 + sgn * ue * kf(ytop) + 0.5) if sgn < 0 then rect(0, ytop, xr, 1, 84, 90, 156) else rect(xr, ytop, W - xr, 1, 84, 90, 156) end local z, j = 0.9, 0 while true do local yt = floor(VY + (H - 1 - VY) / (z * 1.075) + 0.5) local yb = floor(VY + (H - 1 - VY) / (z * 1.02) + 0.5) if yt <= ytop + 1 then break end local k = kf((yt + yb) / 2) for i = 0, 40 do local u0 = ue + 1.8 + i * 5 local xa, xb if sgn < 0 then xa, xb = 32 - (u0 + 3.2) * k, 32 - u0 * k else xa, xb = 32 + u0 * k, 32 + (u0 + 3.2) * k end local x = floor(xa + 0.5) local w = floor(xb + 0.5) - x if w < 1 then w = 1 end if sgn < 0 and x + w <= 0 or sgn > 0 and x >= W then break end window(x, yt, w, yb - yt < 1 and 1 or yb - yt, dark, seed + j * 131 + i * 7) end z, j = z * 1.12, j + 1 end end local SKYBG local function bake() for y = 0, H - 1 do rect(0, y, W, 1, mix(SKY0, SKY1, y > 34 and 1 or y / 34)) end rect(0, 26, W, H - 26, FC[1], FC[2], FC[3]) rect(0, 26, W, 1, 84, 90, 156) rect(33, 19, 1, 7, 60, 64, 120) for y = 29, 59, 5 do local k = kf(y) for x = 20, 44, 4 do if x >= 32 - 14 * k + 2 and x + 2 <= 32 + 11 * k - 1 then window(x, y, 2, 3, FC_D, y * 977 + x * 31) end end end tower(-1, 14, 14, FL, FL_D, 11) tower(1, 11, 8, FR, FR_D, 77) for i = 1, 8 do blend_rect(0, H - 9 + i, W, 1, 214, 120, 60, 0.03 * i) end SKYBG = gfx.snapshot(0, 0, W, H) end local STARS = { { 4, 3 }, { 13, 7 }, { 21, 2 }, { 9, 11 }, { 27, 9 }, { 31, 4 }, { 33, 15 }, { 30, 20 }, { 47, 3 }, { 57, 6 }, { 60, 2 }, { 40, 7 } } local PCYC, PSPD = 420, 0.32 function render() if not SKYBG then bake() end gfx.blit_rgb(SKYBG, 0, 0, W, H) local per = ({ 2, 1, 0.5 })[(cfg.lights or 1) + 1] for i = 1, NB do local p = BP[i] * per if (frame + BPH[i]) % p < p * 0.5 then local c = BC[i] rect(BX[i], BY[i], BW[i], BH[i], c[1], c[2], c[3]) end end for i = 1, #STARS do local s = STARS[i] local a = 0.45 + 0.4 * sin(frame * 0.07 + i * 1.9) blend(s[1], s[2], 230, 232, 255, a) end if (frame // 30) % 2 == 0 then px(33, 18, 255, 60, 50); px(10, 13, 255, 60, 50) end px(46 + (frame // 45) % 2, 7, 255, 60, 50) if cfg.plane ~= false then local n, u = frame // PCYC, frame % PCYC local x = -8 + PSPD * u if x < W + 8 then if n % 2 == 1 then x = W - 1 - x end local ix = floor(x) local f = x - ix local y = 3 blend_rect(ix - 3, y, 7, 1, 150, 150, 200, 0.5) blend_rect(ix, y - 3, 1, 7, 110, 110, 170, 0.4) local function light(dx, dy, r, g, b) blend(ix + dx, y + dy, r, g, b, 1 - f); blend(ix + dx + 1, y + dy, r, g, b, f) end light(0, -3, 255, 50, 50); light(0, 3, 60, 255, 90) if frame % 24 < 2 then light(n % 2 == 1 and 3 or -3, 0, 255, 255, 255) end end end end