info = { type = "image", title = "Cathedral bus", category = "city", author = "BRRRO", version = "1.0", license = "MIT", desc = "Red double-decker passes a lit night cathedral", api = 33, } local tr = ({ sk = { ["Bus speed"] = "Rýchlosť autobusu", ["Passengers"] = "Cestujúci", slow = "pomaly", normal = "normálne", fast = "rýchlo" }, cs = { ["Bus speed"] = "Rychlost autobusu", ["Passengers"] = "Cestující", slow = "pomalu", normal = "normálně", fast = "rychle" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "speed", label = T("Bus speed"), type = "int", default = 1, opts = { T("slow"), T("normal"), T("fast") } }, { key = "people", label = T("Passengers"), type = "bool", default = true }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local floor, sin, cos, max = math.floor, math.sin, math.cos, math.max local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STONE, STONE_L, STONE_D = { 70, 66, 90 }, { 100, 92, 110 }, { 54, 50, 76 } local WIN, WIN_D = { 255, 208, 112 }, { 150, 100, 60 } local RED, RED_D = { 200, 34, 40 }, { 140, 22, 30 } local GROUND = 50 local function c3(c) return c[1], c[2], c[3] end local BG = nil local PEOPLE, BUS_V = true, 0.4 function on_settings() PEOPLE = cfg.people ~= false BUS_V = ({ 0.27, 0.4, 0.6 })[(cfg.speed or 1) + 1] end local function roof(cx, ybase, w, step, c) local y = ybase while w >= 1 do rect(cx - w // 2, y, w, 1, c3(c)) y = y - 1; w = w - step end return y + 1 end local function tower(x, clock) rect(x, 14, 15, GROUND - 14, c3(STONE)) rect(x, 14, 1, GROUND - 14, c3(STONE_L)); rect(x + 14, 14, 1, GROUND - 14, c3(STONE_D)) rect(x, 34, 15, GROUND - 34, c3(STONE_L)); rect(x, 34, 15, 1, c3(STONE)) rect(x - 1, 13, 17, 1, c3(STONE_L)) local top = roof(x + 7, 12, 15, 2, STONE_D) px(x + 7, top - 2, c3(STONE_L)); px(x + 7, top - 1, c3(STONE_L)) rect(x + 3, 15, 3, 3, c3(WIN_D)); rect(x + 9, 15, 3, 3, c3(WIN_D)) if not clock then rect(x + 6, 19, 3, 5, c3(WIN)) end for _, wy in ipairs({ 29, 39 }) do rect(x + 3, wy, 2, 5, c3(WIN)); rect(x + 10, wy, 2, 5, c3(WIN)) px(x + 3, wy - 1, c3(STONE_D)); px(x + 11, wy - 1, c3(STONE_D)) end end local function build_bg() for y = 0, GROUND - 1 do local t = y / GROUND rect(0, y, W, 1, floor(8 + 18 * t), floor(12 + 22 * t), floor(40 + 40 * t)) end for i = 1, 12 do local h = hash32(i * 0x9E3779B1) px(umod(h, W), umod(h >> 8, 11), 200, 204, 240) end rect(20, 24, 24, GROUND - 24, c3(STONE)) rect(20, 36, 24, GROUND - 36, c3(STONE_L)) roof(32, 23, 25, 3, STONE_D) tower(5, true); tower(44, false) rect(29, 25, 7, 7, c3(STONE_D)); rect(30, 24, 5, 9, c3(STONE_D)) rect(30, 26, 5, 5, c3(WIN)); rect(31, 25, 3, 7, c3(WIN)) rect(32, 26, 1, 5, 200, 70, 50); rect(30, 28, 5, 1, 200, 70, 50) rect(29, 38, 7, GROUND - 38, c3(STONE_D)); rect(30, 37, 5, 1, c3(STONE_D)) rect(30, 39, 5, GROUND - 39, c3(WIN)); rect(31, 38, 3, 1, c3(WIN)) rect(32, 40, 1, GROUND - 40, c3(WIN_D)) for _, wx in ipairs({ 22, 25, 39, 42 }) do rect(wx, 40, 1, 5, c3(WIN)) end rect(9, 19, 9, 9, c3(STONE_D)); rect(10, 18, 7, 11, c3(STONE_D)); rect(8, 20, 11, 7, c3(STONE_D)) rect(10, 20, 7, 7, 244, 236, 190) for _, t in ipairs({ { 13, 20 }, { 13, 26 }, { 10, 23 }, { 16, 23 } }) do px(t[1], t[2], 120, 100, 70) end blend_rect(10, 30, 22, 20, 255, 190, 110, 0.07) rect(0, GROUND, W, 5, 74, 70, 90) rect(0, 54, W, 1, 118, 112, 130) rect(0, 55, W, 9, 34, 34, 48) for x = 0, W - 1, 8 do rect(x, 60, 4, 1, 150, 140, 90) end rect(51, 40, 7, 11, c3(RED)); rect(51, 39, 7, 1, c3(RED_D)); px(54, 38, c3(RED_D)) for k = 0, 2 do rect(52, 41 + k * 3, 2, 2, 255, 236, 170); rect(55, 41 + k * 3, 2, 2, 255, 236, 170) end rect(52, 47, 5, 1, c3(RED)); rect(52, 50, 5, 1, c3(RED_D)) blend_rect(49, 50, 11, 4, 255, 220, 150, 0.12) rect(17, 34, 1, 16, 30, 30, 44); rect(17, 33, 4, 1, 30, 30, 44); rect(16, 49, 3, 1, 30, 30, 44) blend_rect(17, 30, 8, 8, 255, 200, 110, 0.1) blend_rect(18, 31, 6, 6, 255, 200, 110, 0.12) rect(20, 34, 3, 2, 255, 230, 160) blend_rect(12, 50, 16, 4, 255, 200, 110, 0.15); blend_rect(15, 50, 10, 4, 255, 200, 110, 0.15) BG = gfx.snapshot(0, 0, W, H) end local function frect(x, y, w, h, c, a) a = a or 1 local ia = floor(x) local xb = x + w local ib = floor(xb) local R, G, B = c3(c) if ib == ia then blend_rect(ia, y, 1, h, R, G, B, a * w) else blend_rect(ia, y, 1, h, R, G, B, a * (1 - (x - ia))) if ib - ia > 1 then blend_rect(ia + 1, y, ib - ia - 1, h, R, G, B, a) end if xb > ib then blend_rect(ib, y, 1, h, R, G, B, a * (xb - ib)) end end end local PEOPLE_U = { 1, 1, 0, 1, 1 } local PEOPLE_L = { 0, 1, 1, 0 } local PASSENGER = { 70, 40, 76 } local BODY = { 200, 34, 40 } local function bus(bx, by) local function f(i, j, w, h, c, a) frect(bx + i, by + j, w, h, c, a) end f(0, 1, 28, 15, BODY); f(1, 0, 26, 1, RED_D); f(0, 14, 28, 2, RED_D) f(0, 8, 28, 1, { 240, 226, 190 }) for i = 0, 4 do local wx = 2 + i * 5 f(wx, 3, 4, 4, WIN) if PEOPLE and PEOPLE_U[i + 1] == 1 then f(wx + 1, 4, 2, 2, PASSENGER); f(wx, 6, 4, 1, PASSENGER) end end for i = 0, 2 do local wx = 2 + i * 5 f(wx, 10, 4, 4, WIN) if PEOPLE and PEOPLE_L[i + 1] == 1 then f(wx + 1, 11, 2, 2, PASSENGER); f(wx, 13, 4, 1, PASSENGER) end end f(17, 9, 4, 7, { 60, 24, 34 }) f(22, 10, 5, 4, WIN) if PEOPLE then f(24, 11, 2, 2, PASSENGER); f(23, 13, 4, 1, PASSENGER) end f(5, 14, 4, 4, { 20, 20, 28 }); f(20, 14, 4, 4, { 20, 20, 28 }) f(6, 15, 2, 2, { 120, 120, 134 }); f(21, 15, 2, 2, { 120, 120, 134 }) f(27, 12, 1, 2, { 255, 246, 210 }) f(-1, 12, 1, 2, { 255, 60, 40 }) end local DIST = 28 + 66 function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local am = frame / (FPS * 20) * 6.28318 for s = 0, 3 do px(floor(13.5 + s * sin(am)), floor(23.5 - s * cos(am)), 50, 40, 30) end for s = 1, 2 do px(floor(13.5 + s * sin(am / 12)), floor(23.5 - s * cos(am / 12)), 50, 40, 30) end local drive = floor(DIST / BUS_V) local u = frame % (drive + 110) if u < drive then local bx = -28 + u * BUS_V blend_rect(floor(bx) + 28, 52, 6, 3, 255, 246, 210, 0.16) blend_rect(floor(bx) + 28, 53, 10, 2, 255, 246, 210, 0.08) bus(bx, 43) end end