info = { type = "image", title = "Spire oasis", category = "city", author = "BRRRO", version = "1.0", license = "MIT", desc = "Alien spires at sunset, a beam and an oasis", api = 44, } local ltr = ({ sk = { ["Dusk"] = "Súmrak", ["Ember"] = "Žiar", ["Rose"] = "Ruža", ["Gold"] = "Zlato", ["Ship"] = "Loď", ["Beam"] = "Lúč" }, cs = { ["Dusk"] = "Soumrak", ["Ember"] = "Žár", ["Rose"] = "Růže", ["Gold"] = "Zlato", ["Ship"] = "Loď", ["Beam"] = "Paprsek" }, })[lang] or {} local function LT(s) return ltr[s] or s end settings = { { key = "dusk", label = LT("Dusk"), type = "int", default = "ember", opts = { keys = { "ember", "rose", "gold" }, LT("Ember"), LT("Rose"), LT("Gold") } }, { key = "ship", label = LT("Ship"), type = "bool", default = true }, { key = "beam", label = LT("Beam"), 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, pi = math.floor, math.sin, math.sqrt, math.pi local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local HZ = 42 local PALS = { ember = { skyT = { 112, 28, 70 }, skyH = { 255, 150, 64 }, sun = { 255, 228, 150 }, twr = { 42, 10, 38 }, far = { 176, 70, 80 }, wd = { 70, 18, 56 }, acc = { 170, 255, 236 } }, rose = { skyT = { 64, 30, 112 }, skyH = { 255, 138, 124 }, sun = { 255, 214, 196 }, twr = { 30, 12, 52 }, far = { 170, 80, 132 }, wd = { 52, 20, 76 }, acc = { 200, 255, 230 } }, gold = { skyT = { 150, 56, 40 }, skyH = { 255, 204, 96 }, sun = { 255, 244, 190 }, twr = { 58, 22, 24 }, far = { 200, 104, 70 }, wd = { 88, 34, 40 }, acc = { 150, 255, 220 } }, } local P = PALS.ember local SX, SY, SR = 44, 32, 12 local function rgb(r, g, b) return floor(r + 0.5), floor(g + 0.5), floor(b + 0.5) end local function lerp3(a, b, t) return a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t, a[3] + (b[3] - a[3]) * t end local function sky_at(y) return lerp3(P.skyT, P.skyH, (y / (HZ - 1)) ^ 1.3) end local function frect(xl, xr, y, h, r, g, b, a) a = a or 1 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 if a >= 1 then rect(il + 1, y, ir - il - 1, h, r, g, b) else blend_rect(il + 1, y, ir - il - 1, h, r, g, b, a) end 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 function st_sky() for y = 0, HZ - 1 do rect(0, y, W, 1, rgb(sky_at(y))) end local R3, R2 = SR + 8, SR + 4 for y = SY - R3, HZ - 1 do local dy = y - SY local sr, sg, sb = sky_at(y) local rings = { { R3, 0.12 }, { R2, 0.28 }, { SR, 1 } } for i = 1, 3 do local R, k = rings[i][1], rings[i][2] if dy * dy < R * R then local hw = floor(sqrt(R * R - dy * dy) + 0.5) local s = P.sun rect(SX - hw, y, 2 * hw, 1, rgb(sr + (s[1] - sr) * k, sg + (s[2] - sg) * k, sb + (s[3] - sb) * k)) end end end end local function vn(i, seed) return (hash32(i * 0x9E3779B1 + seed) & 0x7FFF) / 32767 end local function st_towers() local T, F, A = P.twr, P.far, P.acc for x = 0, W - 1 do local top = 36 - floor(vn(x // 3, 11) * 3) rect(x, top, 1, HZ - top, F[1], F[2], F[3]) end local far = { { 9, 31, 2 }, { 23, 29, 2 }, { 34, 31, 2 }, { 46, 30, 3 }, { 61, 27, 2 } } for i = 1, #far do rect(far[i][1], far[i][2], far[i][3], 40 - far[i][2], F[1], F[2], F[3]) end local function R(x, y, w, h) rect(x, y, w, h, T[1], T[2], T[3]) end R(15, 16, 3, 24); R(13, 19, 7, 3); R(14, 18, 5, 1); R(16, 12, 1, 4) R(13, 26, 7, 1); R(14, 32, 5, 8); R(12, 36, 9, 4) R(29, 26, 3, 14); R(28, 24, 5, 2); R(29, 23, 3, 1); R(30, 19, 1, 4); R(27, 35, 7, 5) R(4, 28, 3, 12); R(2, 27, 7, 2); R(5, 22, 1, 5) R(56, 22, 3, 18); R(55, 21, 5, 1); R(57, 14, 1, 7); R(54, 28, 2, 3); R(59, 30, 2, 3) R(40, 30, 2, 10); R(37, 28, 8, 2); R(38, 27, 6, 1); R(39, 26, 4, 1) R(49, 31, 2, 9); R(48, 30, 4, 1); R(49, 27, 1, 3) rect(0, 39, W, 3, T[1], T[2], T[3]) for x = 0, W - 1 do local h = floor(vn(x // 2, 5) * 3) if h > 0 then R(x, 39 - h, 1, h) end end px(16, 23, A[1] * 0.7, A[2] * 0.7, A[3] * 0.7); px(16, 29, A[1] * 0.7, A[2] * 0.7, A[3] * 0.7) px(16, 35, A[1] * 0.7, A[2] * 0.7, A[3] * 0.7); px(30, 30, A[1] * 0.6, A[2] * 0.6, A[3] * 0.6) end local WROW, TOP = {}, nil local RX0, RX1 = 16, 48 local function st_water() local T = P.twr local rows = {} for y = 0, HZ - 1 do rows[y] = snapshot(0, y, W, 1) end for y = HZ, H - 1 do local d = (y - HZ) / (H - 1 - HZ) blit_rgb(rows[2 * HZ - 1 - y], 0, y, W, 1) blend_rect(0, y, W, 1, P.wd[1], P.wd[2], P.wd[3], 0.3 + 0.45 * d) end local function R(x, y, w, h) rect(x, y, w, h, T[1], T[2], T[3]) end R(0, 58, 13, 6); R(0, 56, 8, 2); R(0, 54, 4, 2); R(52, 59, 12, 5); R(56, 57, 8, 2); R(60, 55, 4, 2) R(9, 47, 1, 11); R(5, 46, 5, 1); R(10, 46, 4, 1); R(3, 47, 2, 1); R(13, 47, 2, 1); R(7, 45, 3, 1) R(59, 48, 1, 9); R(58, 46, 3, 3) for y = HZ + 1, 56 do WROW[y] = snapshot(RX0, y, RX1 - RX0, 1) end TOP = snapshot(0, 0, W, H) end local STAGES = { st_sky, st_towers, st_water } 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 = PALS[cfg.dusk] or PALS.ember TOP, STAGE, PART = nil, 1, nil end local NGL = 8 local GL = {} for i = 1, NGL do local h = hash32(i * 0x85EBCA6B) GL[i] = { y = HZ + 2 + umod(h, 17), dx = umod(h >> 8, 100) / 100 - 0.5, w = 2 + umod(h >> 12, 8) * 0.3, ph = umod(h >> 16, 628) / 100 } end local BX, BY = 16, 11 local function beam(t) local u = t % 12 - 1.5 if u < 0 or u > 3.6 then return end local env = sin(pi * u / 3.6) local A = P.acc blend_rect(BX - 1, 0, 3, BY, A[1], A[2], A[3], 0.2 * env) blend_rect(BX, 0, 1, BY, A[1], A[2], A[3], 0.7 * env) for k = 0, 1 do local y = BY - 1 - (t * 14 + k * 6) % 12 if y >= 0 then blend_rect(BX, floor(y), 1, 2, 255, 255, 255, 0.8 * env) end end blend(BX, BY, 255, 255, 255, env) end local HULL = { { -1, 3, 6 }, { -1, 0, 2 }, { 0, 0, 9 }, { 1, 2, 7 } } local function ship(x, y, mirror) local T, A = P.twr, P.acc for i = 1, #HULL do local s = HULL[i] local yy = y + s[1] if mirror then yy = 2 * HZ - 1 - yy end frect(x + s[2], x + s[3], yy, 1, T[1], T[2], T[3], mirror and 0.5 or 1) end local ey = mirror and 2 * HZ - 1 - y or y frect(x - 5, x, ey, 1, A[1], A[2], A[3], mirror and 0.12 or 0.22) frect(x, x + 1.3, ey, 1, A[1], A[2], A[3], mirror and 0.5 or 1) end function render() if not TOP then build() if not TOP then gfx.ready(false) end return end local t = frame / FPS blit_rgb(TOP, 0, 0, W, H) local p1, p2 = t * 3.2, t * 2.1 for y = HZ + 1, 56 do local d = (y - HZ) / (H - 1 - HZ) local dx = floor((0.5 + 0.9 * d) * (sin(y * 1.1 - p1) + 0.6 * sin(y * 2.3 + p2)) + 0.5) if dx ~= 0 then blit_rgb(WROW[y], RX0 + dx, y, RX1 - RX0, 1) end end local s = P.sun for i = 1, NGL do local g = GL[i] local v = sin(t * g.w + g.ph) if v > 0.2 then local x = floor(SX + g.dx * (10 + (g.y - HZ) * 0.5) + 0.5) blend_rect(x, g.y, 2, 1, s[1], s[2], s[3], (v - 0.2) * 0.9) end end if cfg.beam ~= false then beam(t) end if cfg.ship ~= false then local u = t % 20 - 3 if u > 0 and u < 10.5 then local x = -10 + u * 7.2 ship(x, 33, false) ship(x, 33, true) end end local A = P.acc blend(59, 47, A[1], A[2], A[3], 0.3 + 0.7 * sin(t * 1.7) ^ 2) end