info = { type = "image", title = "Amber sea", category = "nature", author = "BRRRO", version = "1.0", license = "MIT", desc = "Golden sunset over a calm sea with a boat", api = 44, } local tr = ({ sk = { ["Dusk"] = "Súmrak", ["Golden"] = "Zlatý", ["Rose"] = "Ružový", ["Boat"] = "Loďka", ["Glitter"] = "Trblietanie" }, cs = { ["Dusk"] = "Soumrak", ["Golden"] = "Zlatý", ["Rose"] = "Růžový", ["Boat"] = "Loďka", ["Glitter"] = "Třpyt" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "tone", label = T("Dusk"), type = "int", default = "gold", opts = { keys = { "gold", "rose" }, T("Golden"), T("Rose") } }, { key = "boat", label = T("Boat"), type = "bool", default = true }, { key = "glitter", label = T("Glitter"), type = "int", min = 1, max = 5, default = 3 }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local blit_rgb, snapshot, blend_mask = gfx.blit_rgb, gfx.snapshot, gfx.blend_mask 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 HZ = 36 local SX, SY, SR, GR = 30, 31, 10, 24 local TONES = { gold = { top = { 88, 46, 40 }, mid = { 196, 104, 48 }, hor = { 255, 190, 92 }, sun = { 255, 248, 214 }, limb = { 255, 208, 112 }, glow = { 255, 196, 96 }, seaH = { 232, 142, 60 }, seaF = { 78, 36, 34 }, glint = { 255, 236, 170 }, cl = { 255, 178, 100 }, cs = { 170, 78, 46 }, dark = { 34, 18, 22 }, rim = { 226, 126, 52 }, sail = { 84, 38, 30 }, isle = { 156, 76, 44 }, }, rose = { top = { 66, 38, 98 }, mid = { 200, 88, 122 }, hor = { 255, 172, 142 }, sun = { 255, 242, 228 }, limb = { 255, 204, 176 }, glow = { 255, 164, 150 }, seaH = { 222, 112, 124 }, seaF = { 62, 36, 86 }, glint = { 255, 232, 226 }, cl = { 255, 156, 146 }, cs = { 124, 58, 112 }, dark = { 30, 18, 40 }, rim = { 214, 102, 116 }, sail = { 70, 34, 62 }, isle = { 150, 78, 120 }, }, } local P = TONES.gold 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 vn(i, seed) return (hash32(i * 0x9E3779B1 + seed) & 0x7FFF) / 32767 end local function sky_rgb(y) local t = y / (HZ - 1) if t < 0.6 then return mix(P.top, P.mid, t / 0.6) end return mix(P.mid, P.hor, ((t - 0.6) / 0.4) ^ 1.2) end local function st_sky() for y = 0, HZ - 1 do rect(0, y, W, 1, sky_rgb(y)) end end local function st_sun(ya, yb) local g = P.glow for y = ya, min(yb, HZ - 1) do for x = SX - GR, SX + GR do local d = sqrt((x - SX) ^ 2 + (y - SY) ^ 2) if d <= SR - 0.5 then px(x, y, mix(P.sun, P.limb, (d / SR) ^ 2.5)) elseif d < SR + 0.5 then local r, gg, b = mix(P.sun, P.limb, 1) blend(x, y, r, gg, b, SR + 0.5 - d) elseif d < GR then local a = (1 - (d - SR) / (GR - SR)) * 0.72 if a > 0.03 then blend(x, y, g[1], g[2], g[3], a) end end end end end local function st_sea() for y = HZ, H - 1 do local d = (y - HZ) / (H - 1 - HZ) rect(0, y, W, 1, mix(P.seaH, P.seaF, d ^ 0.8)) end blend_rect(0, HZ, W, 1, P.hor[1], P.hor[2], P.hor[3], 0.5) end local function st_path() for y = HZ, H - 1 do local d = (y - HZ) / (H - 1 - HZ) local hw = 3 + 11 * d for x = floor(SX - hw), floor(SX + hw) + 1 do local k = 1 - math.abs(x - SX) / hw if k > 0 then local r, g, b = mix(P.glow, P.sun, k * (1 - d)) blend(x, y, r, g, b, k * (0.8 - 0.5 * d)) end end end end local function st_ripples() for i = 1, 44 do local h = hash32(i * 0x85EBCA6B) local y = HZ + 1 + umod(h, H - HZ - 1) local d = (y - HZ) / (H - 1 - HZ) local len = 2 + floor(d * 6) + umod(h >> 8, 4) local x = umod(h >> 12, W + len) - len if i % 3 == 0 then blend_rect(x, y, len, 1, P.hor[1], P.hor[2], P.hor[3], 0.16) else blend_rect(x, y, len, 1, P.seaF[1], P.seaF[2], P.seaF[3], 0.34) end end for x = 0, 17 do local h = floor(3.2 * sin(x * 0.18 + 0.4) + 0.5) if h > 0 then rect(x, HZ - h, 1, h, mix(P.hor, P.isle, 0.8)) end end for x = 47, 55 do local h = floor(1.6 * sin((x - 47) * 0.39) + 0.5) if h > 0 then rect(x, HZ - h, 1, h, mix(P.hor, P.isle, 0.7)) end end end local function ridge(x) if x >= 37 then local u = min(1, (x - 37) / 26) return floor(61 - 18 * u * u * (3 - 2 * u) + (vn(x, 3) - 0.5) * 1.6 + 0.5) elseif x < 15 then return floor(62 - 7 * (1 - x / 15) ^ 1.5 + (vn(x, 4) - 0.5) * 1.2 + 0.5) end end local function crown(cx, cy, r) for y = cy - r - 1, cy + r + 1 do for x = cx - r - 1, cx + r + 1 do local dx, dy = x - cx, y - cy local d = sqrt(dx * dx + dy * dy) if d <= r + (vn(x * 7 + y, 11) - 0.5) * 1.6 then local lit = -(dx / r) * 0.8 - (dy / r) * 0.3 + 0.15 + (vn(x * 3 + y * 5, 13) - 0.5) * 0.55 lit = max(0, min(1, lit)) px(x, y, mix(P.dark, P.rim, lit ^ 1.2 * 0.9)) end end end end local function st_land() local d = P.dark local top = {} for x = 0, W - 1 do top[x] = ridge(x) end for x = 0, W - 1 do local t = top[x] if t then rect(x, t, 1, H - t, d[1], d[2], d[3]) local nx = x < SX and x + 1 or x - 1 if top[nx] and top[nx] > t then px(x, t, P.rim[1], P.rim[2], P.rim[3]) px(x, t + 1, mix(P.dark, P.rim, 0.45)) end end end local trees = { { 47, 4 }, { 53, 5 }, { 59, 6 }, { 63, 5 }, { 3, 3 }, { 10, 3 } } for i = 1, #trees do local cx, r = trees[i][1], trees[i][2] local g = top[cx] local cy = g - r - 2 rect(cx, cy + r - 1, 1, g - (cy + r - 1), d[1], d[2], d[3]) crown(cx, cy, r) end end local st_masks local STAGES = { function() st_masks() end, st_sky, function() st_sun(0, 21) end, function() st_sun(22, HZ - 1) end, st_sea, st_path, st_ripples, st_land, } local STAGE, PART, BG = 1, nil, nil local function build() if STAGE > 1 then blit_rgb(PART, 0, 0, W, H) end STAGES[STAGE]() PART = snapshot(0, 0, W, H) STAGE = STAGE + 1 if STAGE > #STAGES then BG = PART end end function on_settings() P = TONES[cfg.tone] or TONES.gold BG, STAGE = nil, 1 end local ART = { ".....M......", ".....Ms.....", ".....Mss....", "....sMsss...", "...ssMssss..", "..sssMsssss.", ".....M......", "hhhhhhhhhhhh", ".hhhhhhhhhh.", } local HULL, SAIL = {}, {} function st_masks() for p = 0, 3 do local f = p / 4 local hr, sr = {}, {} for r = 1, #ART do local row = ART[r] for c = 0, 12 do local a, b = row:sub(c + 1, c + 1), row:sub(c, c) local ha = (a == "M" or a == "h") and 1 or 0 local hb = (b == "M" or b == "h") and 1 or 0 local sa = a == "s" and 1 or 0 local sb = b == "s" and 1 or 0 hr[#hr + 1] = string.char(floor(255 * ((1 - f) * ha + f * hb) + 0.5)) sr[#sr + 1] = string.char(floor(255 * ((1 - f) * sa + f * sb) + 0.5)) end end HULL[p], SAIL[p] = table.concat(hr), table.concat(sr) end end local function bar(xl, xr, y, a, c) local il, ir = floor(xl), floor(xr) if ir <= il then return end blend_rect(il + 1, y, ir - il - 1, 1, c[1], c[2], c[3], a) blend_rect(il, y, 1, 1, c[1], c[2], c[3], a * (1 - (xl - il))) blend_rect(ir, y, 1, 1, c[1], c[2], c[3], a * (xr - ir)) end local function boat(t) local bx = (30 + t * 0.55) % (W + 28) - 14 local ix = floor(bx) local p = floor((bx - ix) * 4 + 0.5) if p == 4 then ix, p = ix + 1, 0 end local s = sin(t * 1.15) local top = HZ - 3 + (s > 0.5 and 1 or 0) local d, sl = P.dark, P.sail blend_mask(SAIL[p], sl[1], sl[2], sl[3], ix, top, 13, 9, 13, 9, 0.92) blend_mask(HULL[p], d[1], d[2], d[3], ix, top, 13, 9, 13, 9, 1) for k = 1, 3 do local w = floor(sin(t * 2.3 + k * 1.7) * 0.8 + 0.5) bar(bx + 1 + w, bx + 12 + w, top + 8 + k, 0.4 - k * 0.1, d) end end local CLOUDS = { { 5, 24, 0.9, 4 }, { 11, 30, -0.6, 40 }, { 18, 18, 1.2, 20 }, { 25, 26, 0.7, 50 } } 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 + 2 * L) - L bar(x + L * 0.25, x + L * 0.75, c[1], 0.34, P.cs) bar(x, x + L, c[1] + 1, 0.46, P.cs) bar(x + L * 0.1, x + L * 0.9, c[1] + 2, 0.5, P.cl) bar(x + L * 0.3, x + L * 0.7, c[1] + 3, 0.3, P.cl) end end local NP, NO = 36, 12 local GP, GO = {}, {} for i = 1, NP do local h = hash32(i * 0xC2B2AE35) local y = HZ + 1 + umod(h, H - HZ - 2) GP[i] = { y = y, u = umod(h >> 8, 100) / 50 - 1, len = 1 + floor((y - HZ) / 12) + umod(h >> 14, 2), w = 1.2 + umod(h >> 16, 24) / 10, ph = umod(h >> 20, 628) / 100 } end for i = 1, NO do local h = hash32(i * 0x27D4EB2F) GO[i] = { y = HZ + 2 + umod(h, H - HZ - 3), x = umod(h >> 8, W), len = 2 + umod(h >> 14, 4), w = 0.8 + umod(h >> 16, 16) / 10, ph = umod(h >> 20, 628) / 100 } end local function glints(t) local g = P.glint local n = 6 * (cfg.glitter or 3) + 6 for i = 1, min(n, NP) do local q = GP[i] local v = sin(t * q.w + q.ph) if v > 0 then local d = (q.y - HZ) / (H - 1 - HZ) local hw = 3 + 11 * d local x = floor(SX + q.u * hw + sin(t * 0.5 + q.ph) * 1.2 - q.len * 0.5 + 0.5) blend_rect(x, q.y, q.len, 1, g[1], g[2], g[3], v * v * (0.95 - 0.4 * math.abs(q.u))) end end for i = 1, floor(n / 3) do local q = GO[i] local v = sin(t * q.w + q.ph) if v > 0.2 then blend_rect(q.x, q.y, q.len, 1, g[1], g[2], g[3], (v - 0.2) * 0.35) end end end function render() if not BG then build() if not BG then gfx.ready(false) end return end blit_rgb(BG, 0, 0, W, H) local t = frame / FPS clouds(t) glints(t) if cfg.boat then boat(t) end end