info = { type = "image", title = "Wet fog street", category = "city", author = "BRRRO", version = "1.0", license = "MIT", desc = "Foggy night street, wet road, a car passes", api = 44, } local ltr = ({ sk = { ["Light"] = "Svetlo", ["Sodium"] = "Sodíkové", ["Cool"] = "Studené", ["Fog"] = "Hmla", ["Car"] = "Auto" }, cs = { ["Light"] = "Světlo", ["Sodium"] = "Sodíkové", ["Cool"] = "Studené", ["Fog"] = "Mlha", ["Car"] = "Auto" }, })[lang] or {} local function LT(s) return ltr[s] or s end settings = { { key = "light", label = LT("Light"), type = "int", default = "sodium", opts = { keys = { "sodium", "cool" }, LT("Sodium"), LT("Cool") } }, { key = "fog", label = LT("Fog"), type = "int", min = 0, max = 4, default = 2 }, { key = "car", label = LT("Car"), type = "bool", default = true }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local blit_rgb, snapshot = gfx.blit_rgb, gfx.snapshot local floor, sin, sqrt, min, max = math.floor, math.sin, math.sqrt, math.min, math.max local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local VX, VY = 32, 29 local TONES = { sodium = { lamp = { 255, 176, 84 }, core = { 255, 238, 190 }, fog = { 84, 74, 62 }, fogl = { 168, 150, 120 } }, cool = { lamp = { 150, 190, 255 }, core = { 226, 240, 255 }, fog = { 62, 72, 88 }, fogl = { 124, 144, 172 } }, } local P = TONES.sodium local WALL, SKY0, ROAD0 = { 22, 24, 34 }, { 6, 8, 14 }, { 12, 12, 16 } local function rgb(r, g, b) return floor(r + 0.5), floor(g + 0.5), floor(b + 0.5) end local function blob(cx, cy, rx, ry, r, g, b, a) ry = max(ry, 0.8) for dy = -floor(ry), floor(ry) do local k = 1 - (dy / ry) ^ 2 if k > 0 then local hw = floor(rx * sqrt(k) + 0.5) if hw > 0 then blend_rect(floor(cx) - hw, floor(cy) + dy, 2 * hw, 1, r, g, b, a) end end end end local function frect(xl, xr, y, h, r, g, b, a) local il, ir = floor(xl), floor(xr) if ir == il then blend_rect(il, y, 1, h, r, g, b, (xr - xl) * a) return end if ir > il + 1 then blend_rect(il + 1, y, ir - il - 1, h, r, g, b, a) end local fl, fr = (1 - (xl - il)) * a, (xr - ir) * a if fl > 0.02 then blend_rect(il, y, 1, h, r, g, b, fl) end if fr > 0.02 then blend_rect(ir, y, 1, h, r, g, b, fr) end end local LAMPS = { { 26, 33, 1 }, { 18, 40, 1 }, { 8, 48, 1 }, { 40, 36, -1 }, { 47, 43, -1 }, { 56, 51, -1 } } local function st_bg() local F = P.fog for y = 0, VY do local t = (y / VY) ^ 1.5 rect(0, y, W, 1, rgb(SKY0[1] + (F[1] - SKY0[1]) * t, SKY0[2] + (F[2] - SKY0[2]) * t, SKY0[3] + (F[3] - SKY0[3]) * t)) end for y = VY + 1, H - 1 do local t = min(1, (y - VY - 1) / 22) rect(0, y, W, 1, rgb(F[1] * 0.85 + (ROAD0[1] - F[1] * 0.85) * t, F[2] * 0.85 + (ROAD0[2] - F[2] * 0.85) * t, F[3] * 0.85 + (ROAD0[3] - F[3] * 0.85) * t)) end end local function wall(x0, x1) local f = x0 < 32 for x = x0, x1 do local u = f and x or 63 - x local top, base = floor(4 + 0.85 * u + 0.5), floor(55 - 0.9 * u + 0.5) if base > top then rect(x, top, 1, base - top + 1, WALL[1], WALL[2], WALL[3]) end end for c = 0, 7 do local u = floor(2 + c * 3.2 - c * c * 0.12) local x = f and u or 63 - u local top, base = 4 + 0.85 * u, 55 - 0.9 * u local hgt = base - top local wd = max(1, floor(3 - u * 0.08)) for k = 0, 3 do local y = floor(top + hgt * (0.16 + 0.2 * k) + 0.5) local h = hash32(c * 131 + k * 17 + (f and 1 or 2)) if umod(h, 4) == 0 then rect(x, y, wd, 2, 150, 104, 52) else rect(x, y, wd, 2, 32, 34, 48) end end end end local function st_walls() wall(0, 27) wall(37, 63) local F = P.fog local m = 0.7 rect(28, 25, 4, 6, F[1] * m, F[2] * m, F[3] * m) rect(33, 26, 4, 5, F[1] * m, F[2] * m, F[3] * m) rect(31, 23, 3, 3, F[1] * 0.78, F[2] * 0.78, F[3] * 0.78) end local function lamp(L) local x, g, dir = L[1], L[2], L[3] local top = floor(VY - 1.15 * (g - VY) + 0.5) local hx = x + dir * floor(3 + (g - VY) * 0.35) local R = floor(6 + (g - VY) * 0.45) local lr, lg, lb = P.lamp[1], P.lamp[2], P.lamp[3] for y = max(0, top - R), min(H - 1, top + R) do for xx = max(0, hx - R), min(W - 1, hx + R) do local d = sqrt((xx - hx) ^ 2 + (y - top) ^ 2) if d < R then blend(xx, y, lr, lg, lb, 0.62 * (1 - d / R)) end end end for y = top + 1, g do local hw = 1 + (y - top) * 0.3 blend_rect(floor(hx - hw + 0.5), y, floor(2 * hw + 0.5), 1, lr, lg, lb, 0.06) end for k = 1, 3 do blob(hx, g + 2, R * (1.15 - 0.28 * k), R * 0.3 * (1.15 - 0.28 * k), lr, lg, lb, 0.09) end local len = min(63 - (g + 3), floor((g - top) * 1.2)) for k = 0, len do local w = 1 + floor(R / 8) + floor(k / 10) local j = (hash32(k * 977 + g) >> 3) & 7 blend_rect(hx - w // 2, g + 3 + k, w, 1, lr, lg, lb, 0.45 * (1 - k / len) * (0.55 + 0.45 * j / 7)) end rect(x, top, 1, g - top + 1, 12, 12, 16) rect(min(x, hx), top, math.abs(hx - x) + 1, 1, 12, 12, 16) rect(hx, top + 1, 2, 1, P.core[1], P.core[2], P.core[3]) end local function st_puddles() local F = P.fogl local pd = { { 36, 44, 7, 1.5 }, { 20, 53, 9, 2 }, { 47, 56, 8, 1.8 }, { 30, 36, 4, 1 } } for i = 1, #pd do blob(pd[i][1], pd[i][2], pd[i][3], pd[i][4], F[1], F[2], F[3], 0.12) end end local BG = nil local STAGES = { st_bg, st_walls, function() lamp(LAMPS[1]); lamp(LAMPS[4]); lamp(LAMPS[2]) end, function() lamp(LAMPS[5]); lamp(LAMPS[3]); lamp(LAMPS[6]) end, function() st_puddles(); BG = snapshot(0, 0, W, H) end, } local STAGE, PART = 1, nil local function build() if PART then blit_rgb(PART, 0, 0, W, H) end STAGES[STAGE]() STAGE = STAGE + 1 if STAGE <= #STAGES then PART = snapshot(0, 0, W, H) end end function on_settings() P = TONES[cfg.light] or TONES.sodium BG, STAGE, PART = nil, 1, nil end local FB = {} for i = 1, 4 do local h = hash32(i * 0x9E3779B1) FB[i] = { y = 36 + umod(h, 12), len = 22 + umod(h >> 6, 16), x0 = umod(h >> 10, 100) * 0.9, v = (0.6 + umod(h >> 16, 10) / 10) * (umod(h >> 20, 2) * 2 - 1) } end local function car(z) local w = floor(24 / z + 0.5) local xc = VX - 17 / z local yg = floor(VY + 28 / z + 0.5) local h = max(2, floor(w * 0.55 + 0.5)) local x0 = floor(xc - w / 2 + 0.5) local ly = yg - floor(h * 0.4) local lw = max(1, floor(w / 9)) local sep = max(1, floor(w * 0.32)) local lx1, lx2 = floor(xc) - sep, floor(xc) + sep local C, F = P.core, P.fogl if w > 9 then for k = 1, 2 do blob(xc, yg + w * 0.18, w * (1.1 - 0.3 * k), w * 0.3 * (1.1 - 0.3 * k), 255, 240, 200, 0.07) end for i = 1, 2 do local lx = i == 1 and lx1 or lx2 for k = 0, floor(w * 0.5) do blend_rect(lx, yg + 1 + k, lw, 1, 255, 236, 190, 0.4 * (1 - k / (w * 0.5 + 1))) end end end blob(xc, ly, w * 0.9, h * 0.9, 255, 220, 160, 0.04) rect(x0, yg - floor(h * 0.55), w, floor(h * 0.55), 6, 6, 10) rect(x0 + floor(w * 0.15), yg - h, w - 2 * floor(w * 0.15), h - floor(h * 0.55) + 1, 6, 6, 10) if w > 8 then rect(x0 + floor(w * 0.15), yg - h, w - 2 * floor(w * 0.15), 1, F[1] * 0.7, F[2] * 0.7, F[3] * 0.7) rect(x0 + floor(w * 0.25), yg - h + 1, w - 2 * floor(w * 0.25), max(1, floor(h * 0.25)), 40, 46, 58) end for i = 1, 2 do local lx = i == 1 and lx1 or lx2 blob(lx + lw / 2, ly, 1.3 + w * 0.12, 1 + w * 0.08, 255, 230, 180, 0.3) rect(lx, ly, lw, max(1, floor(lw * 0.7 + 0.5)), 255, 248, 222) end end function render() if not BG then build() if not BG then gfx.ready(false) end return end local t = frame / FPS blit_rgb(BG, 0, 0, W, H) local F = P.fogl for i = 1, cfg.fog or 2 do local b = FB[i] local L = b.len local x = (b.x0 + t * b.v) % (W + 2 * L) - L frect(x + L * 0.2, x + L * 0.8, b.y, 1, F[1], F[2], F[3], 0.1) frect(x, x + L, b.y + 1, 2, F[1], F[2], F[3], 0.12) frect(x + L * 0.1, x + L * 0.9, b.y + 3, 1, F[1], F[2], F[3], 0.08) end for i = 1, #LAMPS do local L = LAMPS[i] local g = L[2] local hx = L[1] + L[3] * floor(3 + (g - VY) * 0.35) blend(hx, floor(VY - 1.15 * (g - VY) + 0.5) + 1, 255, 255, 255, 0.25 + 0.25 * sin(t * 1.3 + i * 1.7)) end if cfg.car ~= false then local u = (t % 24 - 2) / 9.5 if u > 0 and u < 1 then car(8 - 7.4 * u) end end end