info = { type = "image", title = "Coast drive", category = "nature", author = "BRRRO", version = "1.0", license = "MIT", desc = "Palm road into a low sun, seen from a car", api = 33, } local tr = ({ sk = { ["Sky"] = "Obloha", ["Amber"] = "Jantárová", ["Rose"] = "Ružová", ["Speed"] = "Rýchlosť", ["Palms"] = "Palmy" }, cs = { ["Sky"] = "Obloha", ["Amber"] = "Jantarová", ["Rose"] = "Růžová", ["Speed"] = "Rychlost", ["Palms"] = "Palmy" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "mood", label = T("Sky"), type = "int", default = "amber", opts = { keys = { "amber", "rose" }, T("Amber"), T("Rose") } }, { key = "speed", label = T("Speed"), type = "int", min = 1, max = 5, default = 3 }, { key = "palms", label = T("Palms"), type = "int", min = 3, max = 12, default = 6 }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sin, sqrt, max, min, ceil = math.floor, math.sin, math.sqrt, math.max, math.min, math.ceil local hash32 = math.hash32 local W, H, FPS = gfx.W, gfx.H, gfx.FPS local T0 = 0 local HY, VX, K = 26, 34, 37 local SUNX, SUNY = 17, HY - 3 local MOODS = { amber = { top = { 64, 30, 108 }, mid = { 226, 80, 84 }, hor = { 255, 192, 88 }, sun = { 255, 246, 210 }, r1 = { 255, 222, 138 }, r2 = { 255, 202, 112 }, sea1 = { 240, 132, 92 }, sea2 = { 72, 38, 96 }, glit = { 255, 232, 160 }, rd1 = { 176, 92, 70 }, rd2 = { 52, 28, 40 }, glow = { 255, 150, 70 }, line = { 255, 226, 168 }, sa1 = { 196, 110, 64 }, sa2 = { 104, 58, 52 }, ld1 = { 120, 56, 76 }, ld2 = { 52, 30, 52 }, pk = { 22, 10, 28 }, ph = { 150, 70, 84 }, cl1 = { 120, 50, 120 }, cl2 = { 255, 150, 96 }, }, rose = { top = { 44, 32, 112 }, mid = { 214, 72, 122 }, hor = { 255, 170, 120 }, sun = { 255, 240, 230 }, r1 = { 255, 206, 176 }, r2 = { 255, 184, 150 }, sea1 = { 236, 112, 128 }, sea2 = { 60, 36, 104 }, glit = { 255, 214, 200 }, rd1 = { 170, 86, 96 }, rd2 = { 48, 26, 52 }, glow = { 255, 130, 110 }, line = { 255, 214, 196 }, sa1 = { 188, 98, 92 }, sa2 = { 96, 50, 66 }, ld1 = { 112, 52, 92 }, ld2 = { 46, 28, 62 }, pk = { 20, 10, 34 }, ph = { 146, 70, 104 }, cl1 = { 96, 54, 140 }, cl2 = { 255, 150, 160 }, }, } local M = MOODS.amber local BG = nil local V, N, PS = 2, 6, 4 local ZMIN, ZL = 1.35, 24.65 function on_settings() M = MOODS[cfg.mood] or MOODS.amber V = 0.7 + 0.3 * (cfg.speed or 3) N = cfg.palms or 6 PS = ZL / N BG = nil end local function c3(c) return c[1], c[2], c[3] end local function mix(a, b, t) return floor(a[1] + (b[1] - a[1]) * t + 0.5), floor(a[2] + (b[2] - a[2]) * t + 0.5), floor(a[3] + (b[3] - a[3]) * t + 0.5) end local function bar(x, y, w, h, c, a) local x1 = x + w local i, i1 = floor(x), floor(x1) if i1 == i then blend_rect(i, y, 1, h, c[1], c[2], c[3], a * (x1 - x)) return end blend_rect(i, y, 1, h, c[1], c[2], c[3], a * (i + 1 - x)) if i1 > i + 1 then blend_rect(i + 1, y, i1 - i - 1, h, c[1], c[2], c[3], a) end if x1 - i1 > 0.02 then blend_rect(i1, y, 1, h, c[1], c[2], c[3], a * (x1 - i1)) end end local function build_bg() for y = 0, HY do local t = y / HY if t < 0.62 then rect(0, y, W, 1, mix(M.top, M.mid, t / 0.62)) else rect(0, y, W, 1, mix(M.mid, M.hor, (t - 0.62) / 0.38)) end end for y = SUNY - 12, HY do for x = SUNX - 12, SUNX + 12 do local d = sqrt((x - SUNX) ^ 2 + (y - SUNY) ^ 2) if d <= 5.5 then px(x, y, c3(M.sun)) elseif d <= 8.5 then px(x, y, c3(M.r1)) elseif d <= 11.5 then px(x, y, c3(M.r2)) end end end for x = 38, W - 1 do local h = floor(1.4 + 1.3 * sin(x * 0.33) + sin(x * 0.81 + 1) + 0.5) if h > 0 then rect(x, HY - h, 1, h, mix(M.hor, M.ld1, 0.55)) end end for d = 0, K do local y = HY + d if y >= H then break end local t = (d / K) ^ 0.75 local ls, lr = floor(VX - 1.25 * d + 0.5), floor(VX - 0.8 * d + 0.5) local rr, rs = floor(VX + 0.8 * d + 0.5), floor(VX + 1.6 * d + 0.5) rect(0, y, W, 1, mix(M.ld1, M.ld2, t)) if ls > 0 then rect(0, y, ls, 1, mix(M.sea1, M.sea2, min(d / 14, 1))) end if lr > max(ls, 0) then rect(max(ls, 0), y, lr - max(ls, 0), 1, mix(M.sa1, M.sa2, t)) end if rs > rr then rect(rr, y, rs - rr, 1, mix(M.sa1, M.sa2, t)) end rect(lr, y, rr - lr, 1, mix(M.rd1, M.rd2, t)) local hw = max(1, floor(0.28 * d + 0.5)) blend_rect(floor(VX - 0.45 * d) - hw, y, 2 * hw, 1, M.glow[1], M.glow[2], M.glow[3], 0.5 * (1 - d / K) ^ 1.2) local lw = max(1, floor(0.06 * d + 0.5)) rect(lr, y, lw, 1, mix(M.line, M.rd2, t * 0.6)) rect(rr - lw, y, lw, 1, mix(M.line, M.rd2, t * 0.6)) end BG = gfx.snapshot(0, 0, W, H) end local CLOUDS = { { 4, 30, 1.5, 6, "cl1" }, { 11, 24, -1.1, 40, "cl1" }, { 17, 34, 0.8, 22, "cl2" } } local function clouds(t) for i = 1, #CLOUDS do local c = CLOUDS[i] local L = c[2] local x = (c[4] + t * c[3]) % (W + L) - L local col = M[c[5]] bar(x, c[1], L, 1, col, 0.5) bar(x + 3, c[1] + 1, L - 8, 1, col, 0.4) end end local function glitter(t) for d = 1, 8 do local w = (6.5 - 0.65 * d) * (0.5 + 0.5 * sin(t * 2.3 + d * 2.1)) if w > 0.3 then local cx = SUNX + 1.5 * sin(t * 0.9 + d) local x1 = min(cx + w / 2, VX - 1.25 * d - 1) if x1 > cx - w / 2 then bar(cx - w / 2, HY + d, x1 - (cx - w / 2), 1, M.glit, 0.75) end end end end local ZP, DL, ZFAR = 1.6, 0.7, 14 local function dashes(z0) local lc = M.line for j = floor((z0 - DL) / ZP), floor((z0 + ZFAR) / ZP) do local zs = 1 + j * ZP - z0 local ze = zs + DL if ze > 1 and zs < ZFAR then local yb, yt = HY + K / max(zs, 1), HY + K / ze for r = floor(yt), min(ceil(yb) - 1, H - 1) do local cov = min(r + 1, yb) - max(r, yt) if cov > 0.02 then local w = max(1, floor(0.1 * (r + 0.5 - HY) + 0.8)) blend_rect(VX - w // 2, r, w, 1, lc[1], lc[2], lc[3], cov * 0.95) end end end end end local FR = { { -1, -0.3 }, { -0.65, -0.95 }, { -0.1, -1.05 }, { 0.4, -1 }, { 0.85, -0.7 }, { 1, -0.2 }, { -0.5, 0.2 } } local function palm(z, side, r1, r2, r3) local d = K / z local xb, yb = VX + side * (1.55 + 0.7 * r1) * d, HY + d local Hs = (2.2 + 0.7 * r2) * d local xt, yt = xb + side * (r3 - 0.25) * 0.3 * Hs, yb - Hs local Lf = 0.9 * d + 1.5 if xt + Lf < 0 or xt - Lf > W then return end local r, g, b = mix(M.ph, M.pk, min(1, d / 12)) local tw = max(1, 0.15 * d) local seg = d < 6 and 2 or 3 for y = floor(yt), floor(yb) - 1, seg do local p = (y - yt) / Hs local x = xb + (xt - xb) * (1 - p) ^ 1.5 local w = max(1, floor(tw * (0.55 + 0.45 * p) + 0.5)) rect(floor(x + 0.5 - w / 2), y, w, min(seg, floor(yb) - y), r, g, b) end local tf = d >= 22 and 4 or (d >= 11 and 3 or (d >= 6 and 2 or 1)) local lo = d >= 22 and 3 or (d >= 11 and 2 or 1) local steps = min(12, floor(Lf * 0.7) + 2) rect(floor(xt + 0.5) - tf, floor(yt + 0.5) - 1, 2 * tf, tf + 1, r, g, b) for i = 1, #FR do local f = FR[i] for s = 1, steps do local u = s / steps local sz = max(lo, floor(tf * (1.25 - u) + 0.5)) rect(floor(xt + f[1] * Lf * u + 0.5 - sz / 2), floor(yt + (f[2] * u + 0.9 * u * u) * Lf + 0.5), sz, sz, r, g, b) end end end local ZS, SD, R1, R2, R3 = {}, {}, {}, {}, {} local function palms(z0) local n = 0 for k = 1, N do local o = k * PS - z0 local cyc = floor(o / ZL) local h = hash32(k * 977 + cyc * 131 + 0x51ED) n = n + 1 ZS[n] = ZMIN + o - cyc * ZL SD[n] = k % 2 == 0 and 1 or -1 R1[n], R2[n], R3[n] = (h & 255) / 255, ((h >> 8) & 255) / 255, ((h >> 16) & 255) / 255 end for i = 2, n do local j = i while j > 1 and ZS[j - 1] < ZS[j] do ZS[j - 1], ZS[j] = ZS[j], ZS[j - 1] SD[j - 1], SD[j] = SD[j], SD[j - 1] R1[j - 1], R1[j] = R1[j], R1[j - 1] R2[j - 1], R2[j] = R2[j], R2[j - 1] R3[j - 1], R3[j] = R3[j], R3[j - 1] j = j - 1 end end for i = 1, n do palm(ZS[i], SD[i], R1[i], R2[i], R3[i]) end end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local t = (frame + T0) / FPS clouds(t) glitter(t) dashes(t * V) palms(t * V) end