info = { type = "image", title = "Brushstroke sunset", category = "nature", author = "BRRRO", version = "1.0", license = "MIT", desc = "Impressionist sunset sea with a sailboat", api = 44, } local tr = ({ sk = { ["Time of day"] = "Denná doba", ["Sunset"] = "Západ", ["Dusk"] = "Súmrak" }, cs = { ["Time of day"] = "Denní doba", ["Sunset"] = "Západ", ["Dusk"] = "Soumrak" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "time", label = T("Time of day"), type = "int", default = "sunset", opts = { keys = { "sunset", "dusk" }, T("Sunset"), T("Dusk") } }, } local rect, blend_rect = gfx.rect, gfx.blend_rect local floor, sqrt = math.floor, math.sqrt local hash32, umod = math.hash32, math.umod local SKY0, SEA0, CLD0, SUN0, REF0, GLT0, STR0, NCOL = 0, 9, 16, 20, 25, 33, 37, 40 local SETS = { sunset = { sky = { 44,40,120, 74,52,140, 112,62,150, 158,74,140, 204,92,120, 236,124,104, 250,162,96, 255,198,110, 255,226,150 }, sea = { 226,134,124, 176,96,140, 120,76,152, 82,72,160, 52,76,160, 40,96,164, 30,64,120 }, cld = { 112,66,150, 196,100,140, 250,150,120, 255,206,160 }, sun = { 255,244,176, 255,208,88, 255,168,60, 240,120,50, 214,80,56 }, ref = { 255,232,150, 255,196,96, 244,150,70, 255,206,110, 255,244,190, 232,120,74 }, glt = { 255,190,150, 170,130,200, 70,150,190, 120,90,170 }, str = { 0,0,0 }, sx = 40, sy = 31, sr = 8, glow = 2.6, rw = 1.0, clouds = { { 14, 9, 15, 3 }, { 48, 5, 18, 2.5 }, { 22, 20, 16, 2 } }, sail = { 252,236,214, 222,170,170 }, hull = { 70,40,70 }, }, dusk = { sky = { 24,30,96, 36,40,116, 56,44,132, 84,50,140, 122,58,140, 164,66,130, 206,84,116, 236,116,100, 250,150,100 }, sea = { 170,80,120, 120,64,130, 80,58,140, 52,56,142, 36,56,130, 28,50,110, 22,38,86 }, cld = { 60,46,120, 110,56,130, 170,76,124, 222,110,110 }, sun = { 255,170,90, 240,120,70, 210,80,70, 170,56,80, 130,44,84 }, ref = { 170,70,90, 210,96,90, 236,130,84, 140,56,100, 250,160,96, 190,80,96 }, glt = { 160,90,150, 80,100,170, 60,110,150, 110,70,140 }, str = { 250,250,255, 150,160,220, 250,230,200, 90,100,170 }, sx = 40, sy = 38, sr = 7, glow = 1.3, rw = 0.5, clouds = { { 20, 12, 16, 2.5 }, { 50, 22, 14, 2 } }, sail = { 206,150,170, 150,100,140 }, hull = { 36,24,60 }, }, } local HZ = 35 local S, GRID local PAL = {} for i = 1, NCOL * 3 do PAL[i] = 0 end local function clamp(v, lo, hi) return v < lo and lo or (v > hi and hi or v) end local function pick(cx, y, n, h) local sx, sy = S.sx, S.sy if y < HZ then local dx, dy = cx - sx, y - sy local d2 = dx * dx + dy * dy local d = d2 < 484 and sqrt(d2) or 22 if d <= S.sr then return SUN0 + clamp(floor(d / S.sr * 3.0 + n * 1.6), 0, 4) end local cl = S.clouds for i = 1, #cl do local c = cl[i] local ey = (y - c[2]) / c[4] if ey > -1.2 and ey < 1.2 then local ex = (cx - c[1]) / c[3] if ex * ex + ey * ey < 0.8 + n * 0.5 then return CLD0 + clamp(floor((ey + 1) * 1.8 + (n - 0.5) * 1.4), 0, 3) end end end return SKY0 + clamp(floor(y / (HZ - 1) * 8 + (1 - d / 22) * S.glow + (n - 0.5) * 2.4), 0, 8) end local t = (y - HZ) / (63 - HZ) local dx = cx - sx if dx < 0 then dx = -dx end if dx < (1.5 + t * 7) * S.rw * (0.5 + n) and ((h >> 12) & 3) ~= 0 then return REF0 + (h >> 16) % 8 end if (h >> 20) % 6 == 0 then return GLT0 + (h >> 24) % 4 end return SEA0 + clamp(floor(t * 6 + (n - 0.5) * 2.2), 0, 6) end local G, ROW local function build_rows() for y = ROW, ROW + 7 do local row = {} local x = -umod(hash32(y * 0x2545F491), 3) while x < 64 do local h = hash32(y * 0x9E3779B1 + x * 0x85EBCA6B + 0x1234567) local len = 2 + (h & 1) local c = pick(x + 1, y, ((h >> 4) & 255) / 255, h) for i = (x < 0 and 0 or x), (x + len > 64 and 63 or x + len - 1) do row[i + 1] = c end x = x + len end G[y + 1] = row end ROW = ROW + 8 if ROW < 64 then return end if S.str[1] > 0 then for i = 1, 16 do local h = hash32(i * 0x85EBCA6B) G[umod(h >> 8, 22) + 1][umod(h, 64) + 1] = STR0 + i % 3 end end local rows = {} for y = 1, 64 do rows[y] = string.char(table.unpack(G[y], 1, 64)) end GRID = table.concat(rows) end function on_settings() S = SETS[cfg.time] or SETS.sunset local o = 0 for _, k in ipairs({ "sky", "sea", "cld", "sun" }) do local a = S[k] for i = 1, #a do PAL[o + i] = a[i] end o = o + #a end G, ROW, GRID = {}, 0, nil end local function span(x, y, w, c) local ix = floor(x) local f = x - ix if f < 0.04 then rect(ix, y, w, 1, c[1], c[2], c[3]) return end blend_rect(ix, y, 1, 1, c[1], c[2], c[3], 1 - f) if w > 1 then rect(ix + 1, y, w - 1, 1, c[1], c[2], c[3]) end blend_rect(ix + w, y, 1, 1, c[1], c[2], c[3], f) end local SAIL_W = { 1, 1, 2, 2, 3, 3, 4 } local JIB_W = { 0, 0, 0, 1, 1, 2, 2 } local BOAT_V = 1.6 / gfx.FPS local function boat(x) local sail, shade = { S.sail[1], S.sail[2], S.sail[3] }, { S.sail[4], S.sail[5], S.sail[6] } for r = 1, 7 do local y = HZ - 9 + r span(x + 3, y, 1, S.hull) span(x + 4, y, SAIL_W[r], sail) if JIB_W[r] > 0 then span(x + 3 - JIB_W[r], y, JIB_W[r], shade) end end span(x, HZ - 1, 7, S.hull) span(x + 1, HZ, 5, S.hull) blend_rect(floor(x) + 1, HZ + 1, 5, 1, S.hull[1], S.hull[2], S.hull[3], 0.5) end local function tone(set, k, o) local i = (k % (#set // 3)) * 3 PAL[o + 1], PAL[o + 2], PAL[o + 3] = set[i + 1], set[i + 2], set[i + 3] end function render() if not GRID then build_rows() rect(0, 0, 64, 64, S.sky[10], S.sky[11], S.sky[12]) if not GRID then gfx.ready(false) return end end local f = frame for c = 0, 7 do tone(S.ref, f // (5 + c % 3) + c * 7, (REF0 + c) * 3) end for c = 0, 3 do tone(S.glt, f // (9 + c * 2) + c, (GLT0 + c) * 3) end for c = 0, 2 do tone(S.str, f // (12 + c * 5) + c, (STR0 + c) * 3) end gfx.blit_indexed(GRID, PAL, 0, 0, 64, 64, 64, 64) boat((f * BOAT_V + 10) % 88 - 12) end