info = { type = "image", title = "Neon rain lane", category = "city", author = "BRRRO", version = "1.0", license = "MIT", desc = "Camera glides past neon signs in a wet alley", api = 33, } local tr = ({ sk = { ["Rain"] = "Dážď", ["Light"] = "Slabý", ["Normal"] = "Normálny", ["Heavy"] = "Silný" }, cs = { ["Rain"] = "Déšť", ["Light"] = "Slabý", ["Normal"] = "Normální", ["Heavy"] = "Silný" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "rain", label = T("Rain"), type = "int", default = "normal", opts = { keys = { "light", "normal", "heavy" }, T("Light"), T("Normal"), T("Heavy") } }, } local DROPS = { light = 7, normal = 14, heavy = 24 } local rect, blend, blend_rect, blit = gfx.rect, gfx.blend, gfx.blend_rect, gfx.blit_indexed local floor, ceil, sin, abs, max = math.floor, math.ceil, math.sin, math.abs, math.max local hash32, umod = math.hash32, math.umod local W, H = gfx.W, gfx.H local WALL_Y, GROUND_Y = 14, 46 local WALL, GROUND = { 22, 14, 50 }, { 12, 8, 30 } local MAG, CYA = { 255, 60, 225 }, { 40, 225, 255 } local WP, MG = 170, 30 local SPEED = 0.3 local BG local function build_bg() for y = 0, WALL_Y - 1 do local t = y / WALL_Y rect(0, y, W, 1, floor(70 + (WALL[1] - 70) * t + 0.5), floor(34 + (WALL[2] - 34) * t + 0.5), floor(104 + (WALL[3] - 104) * t + 0.5)) end rect(0, WALL_Y, W, GROUND_Y - WALL_Y, WALL[1], WALL[2], WALL[3]) rect(0, 24, W, 1, 30, 20, 66) rect(0, 35, W, 1, 30, 20, 66) rect(0, GROUND_Y - 2, W, 2, 46, 30, 92) rect(0, GROUND_Y, W, H - GROUND_Y, GROUND[1], GROUND[2], GROUND[3]) BG = gfx.snapshot(0, 0, W, H) end local SIGNS = {} local function new_sign(wx, wy, gc, kinds) local s = { wx = wx, wy = wy, gc = gc, kinds = kinds, segs = {}, w = 0, h = 0 } SIGNS[#SIGNS + 1] = s return s end local function seg(s, x, y, w, h, col, grp) s.segs[#s.segs + 1] = { x, y, w, h, col, grp } s.w, s.h = max(s.w, x + w), max(s.h, y + h) end local function glyph(s, gx, gy, bits, col, grp) bits = bits | 0x21 if bits & 1 ~= 0 then seg(s, gx, gy, 8, 1, col, grp) end if bits & 2 ~= 0 then seg(s, gx, gy + 3, 7, 1, col, grp) end if bits & 4 ~= 0 then seg(s, gx, gy + 7, 8, 1, col, grp) end if bits & 8 ~= 0 then seg(s, gx, gy, 1, 5, col, grp) end if bits & 16 ~= 0 then seg(s, gx + 7, gy, 1, 8, col, grp) end if bits & 32 ~= 0 then seg(s, gx + 3, gy, 1, 8, col, grp) end if bits & 64 ~= 0 then seg(s, gx + 4, gy + 5, 3, 1, col, grp) end end local function frame_box(s, w, h, col, grp) seg(s, 0, 0, w, 1, col, grp); seg(s, 0, h - 1, w, 1, col, grp) seg(s, 0, 0, 1, h, col, grp); seg(s, w - 1, 0, 1, h, col, grp) end do local a = new_sign(20, 8, MAG, { 0, 2, 0, 0 }) frame_box(a, 14, 34, CYA, 4) glyph(a, 3, 3, 0x4B, MAG, 1); glyph(a, 3, 13, 0x56, MAG, 2); glyph(a, 3, 23, 0x2D, MAG, 3) local b = new_sign(66, 16, CYA, { 1, 0 }) frame_box(b, 24, 9, CYA, 2) seg(b, 3, 4, 13, 1, MAG, 1); seg(b, 13, 2, 1, 5, MAG, 1); seg(b, 14, 3, 1, 3, MAG, 1); seg(b, 15, 4, 1, 1, MAG, 1) seg(b, 18, 3, 1, 3, MAG, 1); seg(b, 20, 3, 1, 3, MAG, 1) local c = new_sign(110, 20, CYA, { 0, 0 }) seg(c, 0, 0, 1, 18, CYA, 1); seg(c, 3, 0, 1, 18, CYA, 1) seg(c, 0, 3, 4, 1, MAG, 2); seg(c, 0, 9, 4, 1, MAG, 2); seg(c, 0, 15, 4, 1, MAG, 2) local d = new_sign(136, 26, MAG, { 1, 0 }) seg(d, 0, 6, 4, 1, MAG, 1); seg(d, 3, 3, 1, 4, MAG, 1); seg(d, 3, 3, 5, 1, MAG, 1) seg(d, 7, 0, 1, 4, MAG, 1); seg(d, 7, 0, 5, 1, MAG, 1) seg(d, 0, 9, 12, 1, CYA, 2) end local function alpha(kind, seed, f) if kind == 0 then return 0.9 + 0.1 * sin(f * 0.05 + seed) end if kind == 1 then local q = (f + seed * 37) % 200 if q < 14 then return ((hash32((f >> 1) * 31 + seed) & 1) == 0) and 0.12 or 1 end return 0.95 end local q = (f + seed * 53) % 150 if q < 36 then return ((hash32((f >> 1) * 17 + seed + q) & 3) == 0) and 0.1 or 1 end return 0.95 end local function bar(x, y, w, h, c, a) local x1 = x + w local ix0, ix1 = ceil(x), floor(x1) if ix1 > ix0 then blend_rect(ix0, y, ix1 - ix0, h, c[1], c[2], c[3], a) end local f = ix0 - x if f > 0.04 then blend_rect(ix0 - 1, y, 1, h, c[1], c[2], c[3], a * f) end f = x1 - ix1 if f > 0.04 then blend_rect(ix1, y, 1, h, c[1], c[2], c[3], a * f) end end local function draw_sign(s, sx, f) local al, sum = {}, 0 for g = 1, #s.kinds do al[g] = alpha(s.kinds[g], g * 7 + s.wx, f); sum = sum + al[g] end local am = sum / #s.kinds local ix, iy = floor(sx + 0.5), s.wy local gc = s.gc blend_rect(ix - 5, iy - 5, s.w + 10, s.h + 10, gc[1], gc[2], gc[3], 0.05 * am) blend_rect(ix - 3, iy - 3, s.w + 6, s.h + 6, gc[1], gc[2], gc[3], 0.07 * am) blend_rect(ix - 1, iy - 1, s.w + 2, s.h + 2, gc[1], gc[2], gc[3], 0.09 * am) for i = 1, #s.segs do local q = s.segs[i] bar(sx + q[1], iy + q[2], q[3], q[4], q[5], al[q[6]]) end end local NREF = 18 local function reflect(f) rect(0, GROUND_Y, W, H - GROUND_Y, GROUND[1], GROUND[2], GROUND[3]) for i = 0, NREF - 1 do local row = gfx.snapshot(0, GROUND_Y - 1 - i, W, 1) local amp = 0.7 + 0.09 * i local dx = floor(amp * sin(i * 0.9 + f * 0.11) + 0.4 * amp * sin(i * 2.3 - f * 0.07) + 0.5) gfx.blit_rgb(row, dx, GROUND_Y + i, W, 1, nil, nil, nil, 0.85 - 0.025 * i) end end local RING, RW, RH = {}, {}, {} for r = 2, 5 do local hr = max(1, floor(r * 0.6 + 0.5)) local w, h, t = 2 * r + 1, 2 * hr + 1, {} for y = 0, h - 1 do for x = 0, w - 1 do local e = math.sqrt((x - r) ^ 2 + ((y - hr) * r / hr) ^ 2) t[#t + 1] = abs(e - r) < 0.55 and 1 or 0 end end RING[r], RW[r], RH[r] = string.char(table.unpack(t)), w, h end local RPAL = {} for a = 1, 4 do RPAL[a] = { 0, 0, 0, 150 - 28 * (a - 1), 190 - 36 * (a - 1), 250 - 40 * (a - 1) } end local function rain(f, n) for i = 1, n do local h = hash32(i * 0x9E3779B1) local y = (f * 3 + umod(h >> 8, 80)) % 80 - 14 blend_rect(umod(h, W), y, 1, 5, 170, 190, 255, 0.22) end for i = 1, 5 do local P = 19 + umod(hash32(i * 977), 8) local q = f + umod(hash32(i * 131), P) local k, a = floor(q / P), q % P if a < 15 then local h = hash32(i * 7919 + k * 0xC2B2AE35) local r = 2 + a // 5 blit(RING[r], RPAL[1 + a // 4], umod(h, W) - r, GROUND_Y + 5 + umod(h >> 8, 11), RW[r], RH[r], RW[r], RH[r], true) end end end local PIPES = { 52, 100, 158 } local WINDOWS = { 6, 40, 90, 126 } local function px_of(wx, par, X, per, m) return ((wx - X * par + m) % per) - m end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local f = frame local X = f * SPEED for b = 1, 2 do local bx = px_of(b * 61, 0.4, X, 150, 40) blend_rect(bx - 14, 0, 40, 9, MAG[1], MAG[2], MAG[3], 0.05) blend_rect(bx - 8, 0, 28, 6, MAG[1], MAG[2], MAG[3], 0.06) end for i = 1, #PIPES do local sx = px_of(PIPES[i], 1, X, WP, MG) if sx < W then bar(sx, 6, 3, GROUND_Y - 6, { 36, 26, 78 }, 1) bar(sx + 2, 6, 1, GROUND_Y - 6, { 70, 44, 130 }, 0.6) end end for i = 1, #WINDOWS do local sx = px_of(WINDOWS[i], 1, X, WP, MG) if sx < W then bar(sx, 27, 9, 8, { 36, 26, 78 }, 1) bar(sx + 1, 28, 7, 6, { 14, 9, 34 }, 1) end end for i = 1, #SIGNS do local s = SIGNS[i] local sx = px_of(s.wx, 1, X, WP, MG) if sx < W and sx + s.w > 0 then draw_sign(s, sx, f) end end local pole = px_of(100, 1.6, X, 170, 14) if pole < W then bar(pole, 0, 4, GROUND_Y, { 6, 4, 16 }, 1) bar(pole - 1, 0, 1, GROUND_Y, MAG, 0.3) end reflect(f) rain(f, DROPS[cfg.rain] or 14) end