info = { type = "image", title = "Muscle car night", category = "other", author = "BRRRO", version = "1.0", license = "MIT", desc = "Muscle car rumbling down a night road", api = 44, } local tr = ({ sk = { ["Body colour"] = "Farba tela", ["Road speed"] = "Rýchlosť cesty", ["Engine"] = "Motor", ["Still"] = "Bez pohybu", ["Idle"] = "Pokoj", ["Revving"] = "Zvyšovanie otáčok" }, cs = { ["Body colour"] = "Barva těla", ["Road speed"] = "Rychlost silnice", ["Engine"] = "Motor", ["Still"] = "Beze pohybu", ["Idle"] = "Klid", ["Revving"] = "Přidávání plynu" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "body", label = T("Body colour"), type = "color", default = "#C81626" }, { key = "speed", label = T("Road speed"), type = "int", min = 1, max = 6, default = 3 }, { key = "rumble", label = T("Engine"), type = "int", default = 1, opts = { T("Still"), T("Idle"), T("Revving") } }, } local px, rect, blend, brect = gfx.px, gfx.rect, gfx.blend, gfx.blend_rect local floor, sin, abs = math.floor, math.sin, math.abs local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local TAU = 6.28318 local VY = 20 local KEY = { 255, 0, 255 } local function mix(a, b, t) return a + (b - a) * t end local RED, RED_D, RED_L, RED_H = { 200, 22, 38 }, { 140, 14, 28 }, { 240, 76, 70 }, { 255, 150, 130 } local SPEED, RUMBLE = 9, 1 local BG, SPR = nil, nil local SPR_X, SPR_Y, SPR_W, SPR_H = 8, 23, 48, 30 local function build_world() local bands = { { 6, 8, 28 }, { 10, 12, 40 }, { 16, 18, 56 }, { 26, 24, 74 }, { 44, 34, 92 } } for i = 1, 5 do rect(0, (i - 1) * 4, W, 4, bands[i][1], bands[i][2], bands[i][3]) end for i = 1, 16 do local h = hash32(i * 0x9E3779B1) local c = 90 + umod(h >> 16, 120) px(umod(h, W), umod(h >> 8, 14), c, c, 255) end brect(8, 16, 48, 4, 255, 150, 100, 0.10) brect(18, 18, 28, 2, 255, 150, 100, 0.14) for i = 1, 9 do local h = hash32(i * 0x85EBCA6B) px(2 + umod(h, 60), 18 + umod(h >> 8, 2), 255, 210, 120) end for x = 0, W - 1 do if abs(x - 32) > 5 then local h = 2 + umod(hash32(x * 977), 4) + ((x % 7 == 0) and 2 or 0) rect(x, VY - h, 1, h, 4, 10, 12) end end rect(0, VY, W, H - VY, 10, 22, 20) for y = VY, H - 1 do local hw = (y - VY) * 1.23 + 1 local t = (y - VY) / 43 local band = floor(t * 4) local a = 30 + band * 5 rect(floor(32 - hw), y, floor(2 * hw), 1, a, a + 2, a + 16) local e = (y - VY) / 8 if e > 1 then e = 1 end local ec, eb = floor(mix(a, 190, e)), floor(mix(a + 16, 204, e)) rect(floor(32 - 0.95 * hw), y, 1, 1, ec, ec, eb) rect(floor(32 + 0.95 * hw), y, 1, 1, ec, ec, eb) end for i = 1, 70 do local h = hash32(i * 0xC2B2AE35) local y = 40 + umod(h >> 8, 24) local hw = (y - VY) * 1.1 px(floor(32 - hw + umod(h, floor(2 * hw))), y, 60, 62, 78) end rect(12, 54, 40, 2, 6, 6, 10) rect(8, 47, 8, 10, 8, 8, 12); rect(48, 47, 8, 10, 8, 8, 12) rect(8, 48, 1, 8, 40, 40, 52); rect(55, 48, 1, 8, 40, 40, 52) for y = 49, 55, 2 do rect(9, y, 6, 1, 18, 18, 24); rect(49, y, 6, 1, 18, 18, 24) end end local BODY_R = { 9, 10, 11, 12, 14, 15, 17, 18, 19, 20, 21, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 22, 21, 20, 19 } local function body_x(y) local r = BODY_R[y - 22] if not r then return nil end return 32 - r, 31 + r end local LAMPS = { 11, 19, 39, 47 } local function build_sprite() rect(0, 0, W, H, KEY[1], KEY[2], KEY[3]) for y = 23, 51 do local x0, x1 = body_x(y) local c = RED if y == 23 then c = RED_H elseif y <= 25 or y == 36 then c = RED_L elseif y == 37 or y >= 49 then c = RED_D end rect(x0, y, x1 - x0 + 1, 1, c[1], c[2], c[3]) end rect(9, 35, 1, 12, RED_L[1], RED_L[2], RED_L[3]); rect(54, 35, 1, 12, RED_D[1], RED_D[2], RED_D[3]) for y = 26, 32 do local x0, x1 = body_x(y) local k = (y - 26) / 6 rect(x0 + 3, y, x1 - x0 - 5, 1, floor(mix(46, 16, k)), floor(mix(58, 20, k)), floor(mix(108, 44, k))) end for k = 0, 4 do px(24 + k, 27 + k, 110, 136, 196) end rect(13, 33, 38, 1, 200, 206, 220) rect(10, 38, 16, 7, 150, 156, 176); rect(38, 38, 16, 7, 150, 156, 176) rect(11, 39, 14, 5, 44, 6, 10); rect(39, 39, 14, 5, 44, 6, 10) for _, x in ipairs({ 10, 25, 38, 53 }) do px(x, 38, RED[1], RED[2], RED[3]); px(x, 44, RED[1], RED[2], RED[3]) end rect(26, 39, 12, 4, 14, 14, 20) rect(26, 38, 12, 1, 120, 126, 146) rect(9, 46, 46, 1, 238, 242, 250) rect(10, 47, 44, 1, 160, 168, 186) rect(11, 48, 42, 1, 96, 102, 124) rect(27, 43, 10, 5, 70, 72, 70) rect(28, 44, 8, 3, 214, 216, 204) for x = 29, 34, 2 do px(x, 45, 60, 62, 70) end rect(12, 49, 4, 3, 180, 186, 200); rect(48, 49, 4, 3, 180, 186, 200) rect(13, 50, 2, 1, 10, 10, 14); rect(49, 50, 2, 1, 10, 10, 14) SPR = gfx.snapshot(SPR_X, SPR_Y, SPR_W, SPR_H) end local function tail_lamp(x, y, k) brect(x - 3, y - 3, 12, 11, 255, 24, 16, 0.07 * k) brect(x - 1, y - 1, 8, 7, 255, 30, 20, 0.16 * k) rect(x, y, 6, 5, 196, 14, 18) rect(x + 1, y + 1, 4, 3, 255, floor(40 + 30 * k), 34) rect(x + 2, y + 2, 2, 1, 255, 150, 120) px(x, y, 150, 156, 176); px(x + 5, y, 150, 156, 176) px(x, y + 4, 150, 156, 176); px(x + 5, y + 4, 150, 156, 176) end local function exhaust(t, ox, oy) if RUMBLE == 0 then return end local per, life = (RUMBLE == 2) and 4 or 7, 36 local a0 = (RUMBLE == 2) and 0.30 or 0.22 for k = 0, life // per do local birth = (t // per - k) * per local s = (t - birth) / life if s < 1 then local h = hash32(birth * 0x27D4EB2F) local r = floor(1 + 4 * s) local a = a0 * (1 - s) for side = -1, 1, 2 do local x = floor(32 + side * (18 + 7 * s) + umod(h >> (side + 1) * 4, 3) - 1) local y = floor(51 + oy + 11 * s) brect(x - r, y - r, 2 * r + 1, 2 * r + 1, 130, 108, 116, a * 0.6) if r > 1 then brect(x - r + 1, y - r + 1, 2 * r - 1, 2 * r - 1, 144, 122, 130, a) end end end end end local function dashes(t, X, off) local per, len = 4.0, 1.6 local z0 = (-t * SPEED / STEP_HZ + off) % per for k = 0, 6 do local zn = z0 + k * per + 1.0 local zf = zn + len if zn < 14 then local yn = VY + 43 / zn local yf = VY + 43 / (zf > 14 and 14 or zf) local a = 1.4 - zn / 10 if a > 1 then a = 1 elseif a < 0 then a = 0 end local y = floor(yf) local ye = floor(yn) while y <= ye and y < H do local h = ye - y + 1 if h > 2 then h = 2 end local m = y + h * 0.5 local d = m - VY local w = floor(0.07 * 53 * d / 43 + 0.5) if w < 1 then w = 1 end brect(floor(32 + X * 53 * d / 43 - w / 2 + 0.5), y, w, h, 214, 214, 224, a) y = y + h end end end end local function posts(t) local per = 2.0 local z0 = (-t * SPEED / STEP_HZ) % per for k = 0, 11 do local z = z0 + k * per + 1.0 local d = 43 / z local a = 1.4 - z / 10 if a > 1 then a = 1 elseif a < 0 then a = 0 end local sz = floor(2.4 / z + 0.5) if sz < 1 then sz = 1 end for side = -1, 1, 2 do local x = 32 + side * 1.1 * 53 / z if a > 0 and x > -4 and x < 68 then local y = floor(VY + d - 3.5 / z) brect(floor(x), y, sz, sz + 1, 255, 190, 70, a) brect(floor(x), y + sz + 1, 1, floor(d * 0.12) + 1, 20, 24, 30, a) end end end end local function street_lamps(t) local per = 4.0 local z0 = (-t * SPEED / STEP_HZ) % (per * 6) for k = 0, 5 do local z = z0 + k * per + 1.2 local side = (k % 2 == 0) and -1 or 1 local d = 43 / z local yb = VY + d local x = 32 + side * 1.3 * 53 / z local a = 1.3 - z / 14 if a > 1 then a = 1 end if a > 0.1 and x > -8 and x < 72 then local top = yb - 1.7 * 43 / z * 0.9 local pw = z < 2.5 and 2 or 1 local hx = 32 + side * 0.85 * 53 / z brect(floor(x), floor(top), pw, floor(yb - top) + 1, 8, 8, 14, a) local s = floor(3 / z + 1) local hy = floor(top) brect(floor(hx) - s - 2, hy - 2, 2 * s + 5, s + 4, 255, 220, 140, 0.10 * a) brect(floor(hx) - s, hy - 1, 2 * s + 1, s + 2, 255, 226, 150, 0.2 * a) brect(floor(hx) - s + 1, hy, 2 * s - 1, s, 255, 244, 200, a) brect(floor(x < hx and x or hx), hy + s, floor(abs(hx - x)) + 1, 1, 8, 8, 14, a) end end end local function sparkle(t) local n = t // 42 local f = t % 42 if f < 9 then local h = hash32(n * 0x9E3779B1) local x, y = 11 + umod(h, 42), 46 local r = f < 5 and f // 2 or (9 - f) // 2 return x, y, r end end function on_settings() local c = cfg.body or { r = 200, g = 22, b = 38 } RED = { c.r, c.g, c.b } RED_D = { c.r * 0.7, c.g * 0.65, c.b * 0.72 } RED_L = { mix(c.r, 255, 0.3), mix(c.g, 255, 0.3), mix(c.b, 255, 0.3) } RED_H = { mix(c.r, 255, 0.6), mix(c.g, 255, 0.6), mix(c.b, 255, 0.6) } SPEED = 4 + 2 * (cfg.speed or 3) RUMBLE = cfg.rumble or 1 BG, SPR = nil, nil end function render() if not BG then build_world() BG = gfx.snapshot(0, 0, W, H) gfx.ready(false) return end if not SPR then build_sprite() gfx.blit_rgb(BG, 0, 0, W, H) gfx.ready(false) return end local t = frame * STEP_HZ // FPS gfx.blit_rgb(BG, 0, 0, W, H) dashes(t, -0.5, 0) dashes(t, 0.5, 0) posts(t) street_lamps(t) local ox, oy = 0, 0 if RUMBLE > 0 then local h = hash32((t // 2) * 0x9E3779B1) if (h & 3) == 0 then oy = 1 end if RUMBLE == 2 and (t % 150) < 24 then oy = umod(h >> 4, 3) - 1 ox = umod(h >> 8, 3) - 1 end end local revving = RUMBLE == 2 and (t % 150) < 24 local lk = 0.85 + 0.15 * sin(TAU * t / 40) brect(8, 55, 48, 3, 255, 36, 24, 0.08 * lk) brect(14, 58, 36, 6, 255, 36, 24, 0.05 * lk) gfx.blit_rgb(SPR, SPR_X + ox, SPR_Y + oy, SPR_W, SPR_H, KEY[1], KEY[2], KEY[3]) for i = 1, 4 do tail_lamp(LAMPS[i] + ox, 39 + oy, lk) end exhaust(t, ox, oy) if revving and (hash32(t * 0x165667B1) & 3) == 0 then for side = -1, 1, 2 do local x = 32 + side * 18 + ox brect(x - 3, 49 + oy, 6, 5, 255, 150, 40, 0.25) rect(x - 1, 51 + oy, 2, 2, 255, 210, 90) px(x - 1 + umod(t, 2), 53 + oy, 120, 170, 255) end end local sx, sy, r = sparkle(t) if sx then sx, sy = sx + ox, sy + oy + (RUMBLE == 2 and ((t % 3) - 1) or 0) px(sx, sy, 255, 255, 255) if r > 0 then rect(sx - r, sy, 2 * r + 1, 1, 255, 255, 240) rect(sx, sy - r, 1, 2 * r + 1, 255, 255, 240) end end end