info = { type = "image", title = "Tram stop", category = "city", author = "BRRRO", version = "1.0", license = "MIT", desc = "Pastel tram stops in a rainy street", api = 33, } local tr = ({ sk = { ["Rain"] = "Dážď", ["Tram"] = "Električka", ["Mint"] = "Mätová", ["Pink"] = "Ružová", ["Sand"] = "Piesková" }, cs = { ["Rain"] = "Déšť", ["Tram"] = "Tramvaj", ["Mint"] = "Mátová", ["Pink"] = "Růžová", ["Sand"] = "Písková" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "rain", label = T("Rain"), type = "int", min = 1, max = 5, default = 3 }, { key = "tram", label = T("Tram"), type = "int", default = "mint", opts = { keys = { "mint", "pink", "sand" }, T("Mint"), T("Pink"), T("Sand") } }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local floor = math.floor local W, H = gfx.W, gfx.H local function rn(a, b) return math.hash32(a * 7919 + b * 104729) & 0x7FFF end local C, XS, TL = 600, 9, 46 local YG = 52 local BG local PAL = { mint = { body = { 156, 226, 196 }, roof = { 214, 242, 230 }, stripe = { 56, 160, 158 } }, pink = { body = { 246, 190, 204 }, roof = { 252, 226, 232 }, stripe = { 70, 150, 160 } }, sand = { body = { 242, 224, 176 }, roof = { 252, 242, 214 }, stripe = { 60, 150, 150 } }, } local COL = { skirt = { 30, 54, 66 }, dark = { 26, 46, 58 }, glass = { 226, 240, 214 }, cab = { 60, 138, 164 }, lamp = { 255, 236, 166 }, inter = { 40, 70, 84 }, hub = { 128, 158, 168 }, } local function build_bg() for y = 0, 16 do rect(0, y, W, 1, 140 + y * 4, 200 + y * 2, 226 + y // 2) end rect(0, 9, W, 1, 44, 100, 110) local B = { { 0, 18, 13, { 46, 122, 132 }, { 40, 100, 112 }, { 40, 100, 112 } }, { 18, 16, 17, { 112, 178, 178 }, { 240, 160, 184 }, { 242, 232, 222 } }, { 34, 16, 12, { 34, 96, 112 }, { 250, 214, 130 }, { 242, 232, 222 } }, { 50, 14, 15, { 130, 192, 186 }, { 240, 160, 184 }, { 242, 232, 222 } }, } for bi, b in ipairs(B) do local x, w, top, wall = b[1], b[2], b[3], b[4] rect(x, top, w, 41 - top, wall[1], wall[2], wall[3]) rect(x, top, w, 1, wall[1] // 2, wall[2] // 2, wall[3] // 2 + 8) for wy = top + 4, 24, 7 do for wx = x + 2, x + w - 5, 5 do if rn(bi, wx * 8 + wy) % 3 == 0 then rect(wx, wy, 3, 4, 250, 222, 150) else rect(wx, wy, 3, 4, 28, 70, 88) end end end for sx = x, x + w - 1, 2 do rect(sx, 29, 2, 3, sx % 4 == 0 and b[5][1] or b[6][1], sx % 4 == 0 and b[5][2] or b[6][2], sx % 4 == 0 and b[5][3] or b[6][3]) end rect(x + 1, 33, w - 2, 7, 252, 226, 160) for sx = x + 5, x + w - 3, 5 do rect(sx, 33, 1, 7, 70, 100, 100) end end rect(3, 13, 4, 16, 240, 120, 170) for k = 0, 3 do rect(4, 15 + k * 4, 2, 2, 250, 232, 236) end for _, lx in ipairs({ 13, 57 }) do rect(lx, 22, 1, 20, 24, 56, 66) rect(lx - 1, 19, 3, 3, 255, 226, 150) end rect(0, 41, W, 5, 226, 214, 220) rect(0, 41, W, 1, 244, 236, 240) rect(0, 46, W, 1, 60, 86, 100) for y = 47, H - 1 do local t = (y - 47) / 16 rect(0, y, W, 1, floor(72 - 38 * t), floor(90 - 46 * t), floor(114 - 42 * t)) end rect(0, YG, W, 1, 176, 200, 210) rect(0, YG + 1, W, 1, 24, 32, 52) for i = 1, 12 do blend_rect(rn(i, 1) % 56, 55 + rn(i, 2) % 8, 3 + rn(i, 3) % 5, 1, 190, 220, 226, 0.14) end BG = gfx.snapshot(0, 0, W, H) end local function frect(x, y, w, h, c, a, mirror) if mirror then y = 2 * YG - y - h end if y > H - 1 then return end local ix = floor(x) local f = x - ix local r, g, b = c[1], c[2], c[3] if a then blend_rect(ix + 1, y, w - 1, h, r, g, b, a) blend_rect(ix, y, 1, h, r, g, b, a * (1 - f)) blend_rect(ix + w, y, 1, h, r, g, b, a * f) else 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 end local function fpx(x, y, c) local ix = floor(x) local f = x - ix blend(ix, y, c[1], c[2], c[3], 1 - f) blend(ix + 1, y, c[1], c[2], c[3], f) end local OPS = { { 2, 28, 44, 20, "body" }, { 0, 34, 2, 14, "body" }, { 1, 31, 1, 3, "body" }, { 2, 26, 42, 2, "roof" }, { 4, 25, 38, 1, "roof" }, { 18, 23, 9, 2, "stripe" }, { 0, 43, 46, 4, "stripe" }, { 3, 47, 40, 2, "skirt" }, { 2, 30, 6, 8, "cab" }, { 11, 30, 7, 8, "glass" }, { 20, 30, 7, 8, "glass" }, { 37, 30, 7, 8, "glass" }, { 0, 40, 1, 2, "lamp" }, { 5, 48, 3, 3, "dark" }, { 10, 48, 3, 3, "dark" }, { 34, 48, 3, 3, "dark" }, { 39, 48, 3, 3, "dark" }, } local function tram(x, p, open, rolling, mirror) local a = mirror and 0.3 or nil for i = 1, #OPS do local o = OPS[i] local c = p[o[5]] or COL[o[5]] if not mirror or o[2] + o[4] > 40 then frect(x + o[1], o[2], o[3], o[4], c, a, mirror) end end if mirror then return end frect(x + 28, 29, 8, 18, COL.inter) frect(x + 29, 38, 6, 8, COL.lamp) local lw = 1 + 3 * (1 - open) frect(x + 28, 29, lw, 18, p.body) frect(x + 36 - lw, 29, lw, 18, p.body) if open < 0.4 then frect(x + 30, 31, 4, 6, COL.glass) end frect(x + 28, 43, lw, 4, p.stripe) frect(x + 36 - lw, 43, lw, 4, p.stripe) if rolling then local k = floor(x * 0.7) % 3 for _, wx in ipairs({ 5, 10, 34, 39 }) do fpx(x + wx + k * 0.7, 49, COL.hub) end end for k = 0, 5 do fpx(x + 19 + k * 0.9, 24 - k * 1.6, COL.dark) end for k = 0, 4 do fpx(x + 24 + k * 0.5 - 2.4, 16 - k * 1.7, COL.dark) end frect(x + 19, 8, 7, 1, COL.dark) end local function tram_pos(t) if t < 140 then local s = 1 - t / 140 return XS + 72 * s * s, 0, true elseif t < 380 then local o = 0 if t >= 165 and t < 180 then o = (t - 165) / 15 elseif t >= 180 and t < 345 then o = 1 elseif t >= 345 and t < 360 then o = 1 - (t - 345) / 15 end return XS, o, false elseif t < 530 then local u = (t - 380) / 150 return XS - 62 * u * u, 0, true end return nil end local UMB, SKIN, COAT = { 240, 130, 170 }, { 240, 200, 170 }, { 44, 60, 96 } local function walker() local x = 70 - (frame % 340) * 0.2 frect(x - 3, 34, 9, 1, UMB) frect(x - 2, 33, 7, 1, UMB) frect(x + 1, 36, 1, 1, COAT) frect(x, 37, 2, 2, SKIN) frect(x, 39, 2, 4, COAT) frect(x + (frame // 8) % 2, 43, 1, 2, COAT) end local function street_lights() for _, lx in ipairs({ 13, 57 }) do for y = 54, 63 do local sx = lx - 1 + floor(math.sin(frame * 0.12 + y * 0.9 + lx) * 0.9 + 1.5) blend_rect(sx, y, 2, 1, 255, 226, 150, 0.30 - (y - 54) * 0.02) end end for i = 1, 5 do local P = 30 local t = frame + rn(i, 0) % P local k, u = t // P, t % P if u < 22 then local x, y = 6 + rn(i, k * 2 + 1) % 52, 55 + rn(i, k * 2 + 2) % 8 local r = 1 + u // 6 local a = 0.4 * (1 - u / 22) blend_rect(x - r + 1, y - 1, 2 * r - 1, 1, 210, 232, 238, a) blend_rect(x - r + 1, y + 1, 2 * r - 1, 1, 210, 232, 238, a) blend(x - r, y, 210, 232, 238, a) blend(x + r, y, 210, 232, 238, a) end end end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) walker() street_lights() local p = PAL[cfg.tram or "mint"] or PAL.mint local x, open, rolling = tram_pos((frame + 40) % C) if x then gfx.clip(0, YG + 1, W, H - YG - 1) tram(x, p, 0, false, true) gfx.clip() tram(x, p, open, rolling, false) end local n = (cfg.rain or 3) * 4 for i = 1, n do local y = (frame * 3 + rn(i, 7)) % 80 - 12 blend_rect(rn(i, 8) % W, y, 1, 3, 214, 238, 242, 0.3) end end