info = { type = "image", title = "Night sky", category = "space", author = "BRRRO", version = "1.0", license = "MIT", desc = "Turning starry sky over a cabin in the hills", api = 39, } permissions = { "location" } local ltr = ({ sk = { ["Meteors"] = "Meteory", ["a shooting star now and then"] = "občas padajúca hviezda", ["Landscape"] = "Krajina", ["hills, trees and a cabin along the bottom edge"] = "kopce, stromy a chata pri spodnom okraji", ["Sky rotation"] = "Otáčanie oblohy", ["still"] = "bez pohybu", ["slow"] = "pomaly", ["faster"] = "rýchlejšie", ["Moon"] = "Mesiac", ["in today's real phase"] = "v dnešnej skutočnej fáze", ["Stars appear and fade"] = "Hviezdy sa objavujú a miznú", ["slowly showing up in different places"] = "pomaly sa objavuje na rôznych miestach", ["Cloud"] = "Oblak", ["drifts across the sky now and then"] = "občas sa preženie po oblohe", ["Star count"] = "Počet hviezd", ["sparse"] = "riedko", ["normal"] = "normálne", ["dense"] = "husto", ["Satellite"] = "Satelit", ["a steady dot crossing the sky now and then"] = "občas pomaly preletí bodka po oblohe" }, cs = { ["Meteors"] = "Meteory", ["a shooting star now and then"] = "občas padající hvězda", ["Landscape"] = "Krajina", ["hills, trees and a cabin along the bottom edge"] = "kopce, stromy a chata u spodního okraje", ["Sky rotation"] = "Otáčení oblohy", ["still"] = "beze pohybu", ["slow"] = "pomalu", ["faster"] = "rychleji", ["Moon"] = "Měsíc", ["in today's real phase"] = "v dnešní skutečné fázi", ["Stars appear and fade"] = "Hvězdy se objevují a mizí", ["slowly showing up in different places"] = "pomalu se objevuje na různých místech", ["Cloud"] = "Mrak", ["drifts across the sky now and then"] = "občas se přežene po obloze", ["Star count"] = "Počet hvězd", ["sparse"] = "řídce", ["normal"] = "normálně", ["dense"] = "hustě", ["Satellite"] = "Satelit", ["a steady dot crossing the sky now and then"] = "občas pomalu přeletí tečka po obloze" }, })[lang] or {} local function LT(s) return ltr[s] or s end settings = { { key = "meteors", type = "bool", default = true, label = LT("Meteors"), hint = LT("a shooting star now and then") }, { key = "land", type = "bool", default = true, label = LT("Landscape"), hint = LT("hills, trees and a cabin along the bottom edge") }, { key = "drift", type = "int", default = "slow", label = LT("Sky rotation"), opts = { keys = { "still", "slow", "faster" }, LT("still"), LT("slow"), LT("faster") } }, { key = "moon", type = "bool", default = true, label = LT("Moon"), hint = LT("in today's real phase") }, { key = "born", type = "bool", default = true, label = LT("Stars appear and fade"), hint = LT("slowly showing up in different places") }, { key = "cloud", type = "bool", default = true, label = LT("Cloud"), hint = LT("drifts across the sky now and then") }, { key = "stars", type = "int", default = "normal", label = LT("Star count"), opts = { keys = { "sparse", "normal", "dense" }, LT("sparse"), LT("normal"), LT("dense") } }, { key = "satellite", type = "bool", default = true, label = LT("Satellite"), hint = LT("a steady dot crossing the sky now and then") }, } local blend, rect = gfx.blend, gfx.rect local floor, ceil, sin, cos, sqrt, fmod, abs = math.floor, math.ceil, math.sin, math.cos, math.sqrt, math.fmod, math.abs local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local PI2 = 2 * math.pi local LAND_TOP, LAND_Y0 = 50, 38 local MAX_STAR = 120 local N_STARS = { sparse = 45, normal = 80, dense = 120 } local DRIFT_T = { still = 0, slow = 180, faster = 42 } local SKY = { 20, 28, 96 } local HOR = { 122, 64, 182 } local GLOW_N = 16 local A_MIN = 0.06 local VEIL_A, VEIL_B = { 205, 110, 240 }, { 105, 140, 250 } local VEIL_HW, VEIL_K = 7.0, 0.46 local BAND_Y, BAND_A, BAND_W, BAND_PH = 22, 13, 5, 3.33 local PARALLAX = { 0.85, 1.00, 1.15 } local BASE = { 0.55, 0.78, 1.00 } local TWA = { 0.18, 0.12, 0.06 } local STAR_PAL = { { 255, 255, 255 }, { 200, 215, 255 }, { 255, 235, 200 }, { 255, 205, 160 } } local FADE = 2 * FPS local MOON_X, MOON_Y, MOON_R = 46, 13, 6 local MOON_RX = 6.2 local LIT, MARE, HALO = { 245, 246, 230 }, { 206, 208, 196 }, { 150, 160, 235 } local HALO_G, HALO_K = 4.0, 0.40 local MARES = { { -3, -3, 3 }, { 2, 1, 3 }, { -2, 4, 2 } } local CL_BODY, CL_RIM = { 50, 58, 140 }, { 176, 186, 240 } local KEY = { 255, 0, 255 } local RIDGE_C = { 40, 24, 90 } local CREST = { 82, 74, 166 } local PATH_C = { 62, 56, 128 } local WIN = { 255, 186, 86 } local SMOKE = { 196, 196, 228 } local rng = 0xB5297A4D local function rnd() rng = (rng ~ (rng << 13)) & 0xFFFFFFFF rng = rng ~ (rng >> 17) rng = (rng ~ (rng << 5)) & 0xFFFFFFFF return rng end local function frnd(a, b) return a + (b - a) * (umod(rnd(), 1000) / 999.0) end local function bl(x, y, r, g, b, a) if a >= 1 - A_MIN then rect(x, y, 1, 1, r, g, b) elseif a >= A_MIN then blend(x, y, r, g, b, a) end 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 sky_h, P, born_now = LAND_TOP, 0, nil local seeded, last_frame, boot = false, 0, true local sbx, sy, smag, sper = {}, {}, {}, {} local scr, scg, scb, sb0, sbt = {}, {}, {}, {}, {} local slen, soff, sn, stwr, stwp = {}, {}, {}, {}, {} local function ox_at(f) if P == 0 then return 0.0 end return (f % P) * W / P end local hs = 0 local function hu() hs = hash32(hs + 0x6D2B79F5); return umod(hs, 1000) / 999.0 end local function place(i, n, f) hs = hash32(i * 0x9E3779B1 + n * 0x85EBCA6B) local bx, y, mag, pal = hu() * W, 0, 0, 1 local c = floor(hu() * 10) if i % 3 ~= 0 then y = BAND_Y + BAND_A * sin(PI2 * bx / W + BAND_PH) + (hu() - hu()) * BAND_W mag = hu() < 0.7 and 0 or 1 pal = c < 5 and 1 or (c < 8 and 2 or 3) else y = hu() * (sky_h - 2) mag = c < 2 and 2 or (c < 6 and 1 or 0) pal = hu() < 0.5 and 1 or 2 + floor(hu() * 2.99) end y = floor(y + 0.5) if y < 0 then y = 0 elseif y > sky_h - 2 then y = sky_h - 2 end local sp = 0 if P > 0 then sp = floor(P / (PARALLAX[mag + 1] + (hu() - 0.5) * 0.12) + 0.5) end local x = bx + ox_at(f) if sp > 0 then x = x - (f % sp) * W / sp end local col = STAR_PAL[pal] sbx[i], sy[i], smag[i], sper[i], sn[i] = x % W, y, mag, sp, n scr[i], scg[i], scb[i], sb0[i], sbt[i] = col[1], col[2], col[3], BASE[mag + 1], TWA[mag + 1] end local function unplace() for i = 1, MAX_STAR do sn[i] = -1 end end local meteor = { on = false, x = 0, y = 0, vx = 0, vy = 0, life = 0 } local sat = { on = false, x = 0, y = 0, vx = 0 } local cloud = { on = false, x = 0, y = 0, sp = 0, n = 0, dome = {}, top = {}, bot = {} } local next_meteor, next_sat, next_cloud = 0, 0, 0 local MET_VX, MET_VY = 102 / FPS, 51 / FPS local CL_HW, CL_BASE = 20, 1.0 local CLM, clm_q = nil, -1 local function cloud_profile() local dm, top, bot = cloud.dome, cloud.top, cloud.bot for i = 1, 2 * CL_HW + 1 do local u, t = i - CL_HW - 1, nil for k = 1, cloud.n do local d = dm[k] local q = (u - d.cx) / d.w if q > -1 and q < 1 then local y = -d.h * sqrt(1 - q * q) if not t or y < t then t = y end end end if t then top[i], bot[i] = t, CL_BASE else top[i], bot[i] = 0, 0 end end end local function new_cloud(x, to_right) cloud.on = true local sp = frnd(0.6, 1.32) / FPS cloud.sp = to_right and sp or -sp cloud.x = x cloud.y = 8 + umod(rnd(), 12) cloud.n = 4 + umod(rnd(), 3) for k = 1, cloud.n do local w = frnd(3.5, 6.5) cloud.dome[k] = { cx = -11 + 22 * (k - 1) / (cloud.n - 1) + frnd(-1.5, 1.5), w = w, h = w * frnd(0.5, 1.2) } end cloud_profile() clm_q = -1 end local function seed(f) rng = 0xB5297A4D for i = 1, MAX_STAR do slen[i] = (25 + umod(rnd(), 70)) * FPS + 2 * FADE soff[i] = umod(rnd(), slen[i]) stwr[i] = frnd(3.0, 7.8) / FPS * 64 / PI2 stwp[i] = frnd(0, 64) end unplace() meteor.on, sat.on = false, false next_meteor = f + 3 * FPS + umod(rnd(), 3 * FPS) next_sat = f + 12 * FPS new_cloud(9.0, true) next_cloud = 0 end local function step_meteor(f) if meteor.on then meteor.x, meteor.y = meteor.x + meteor.vx, meteor.y + meteor.vy meteor.life = meteor.life - 1 if meteor.life <= 0 or meteor.y > sky_h or meteor.x < -8 or meteor.x > W + 8 then meteor.on = false end return end if f < next_meteor then return end meteor.on = true meteor.x, meteor.y = frnd(6, W - 6), frnd(2, 16) meteor.vx = (rnd() & 1) == 1 and -MET_VX or MET_VX meteor.vy = MET_VY meteor.life = floor((8 + umod(rnd(), 5)) * FPS / 30) next_meteor = f + 8 * FPS + umod(rnd(), 23 * FPS) end local function step_sat(f) if sat.on then sat.x = sat.x + sat.vx if sat.x < -2 or sat.x > W + 1 then sat.on = false; next_sat = f + 60 * FPS + umod(rnd(), 120 * FPS) end return end if f < next_sat then return end sat.on = true local to_right = (rnd() & 1) == 1 local v = frnd(4.0, 7.0) / FPS sat.vx = to_right and v or -v sat.x = to_right and -1 or W sat.y = 4 + umod(rnd(), 26) end local function step_cloud(f) if cloud.on then cloud.x = cloud.x + cloud.sp if cloud.x > W + CL_HW + 1 or cloud.x < -CL_HW - 1 then cloud.on = false next_cloud = f + 30 * FPS + umod(rnd(), 60 * FPS) end return end if f < next_cloud then return end local to_right = (rnd() & 1) == 1 new_cloud(to_right and -CL_HW - 1 or W + CL_HW + 1, to_right) end local function span_aa(y, xa, xb, r, g, b) local ia, ib = floor(xa), floor(xb) if ia == ib then bl(ia, y, r, g, b, xb - xa); return end bl(ia, y, r, g, b, ia + 1 - xa) if ib - ia > 1 then rect(ia + 1, y, ib - ia - 1, 1, r, g, b) end bl(ib, y, r, g, b, xb - ib) end local function lit_span(dy, c, waxing) local r2 = MOON_RX * MOON_RX - dy * dy if r2 <= 0 then return nil end local xr = sqrt(r2) if waxing then return c * xr, xr end return -xr, -c * xr end local function moon_phase() local t, m = data.time, data.moon if t and t.ok and m then return m.phase, m.lit end return 0.38, 0.85 end local HALO_N = 2 * (MOON_R + 5) + 1 local HALO_X, HALO_Y = MOON_X - MOON_R - 5, MOON_Y - MOON_R - 5 local HALO_M, halo_q = nil, -1 local function halo_mask(cx, lit) local q = floor((cx - MOON_X - 0.5) * 4 + 0.5) if q == halo_q then return HALO_M end local hk = HALO_K * lit local R0, RG = MOON_R + 0.5, MOON_R + 0.5 + HALO_G local row, rows = {}, {} for j = 1, HALO_N do local dy = HALO_Y + j - 1 - MOON_Y for i = 1, HALO_N do local dx = HALO_X + i - 0.5 - cx local d = sqrt(dx * dx + dy * dy) local a = hk * (RG - d) / HALO_G row[i] = (d > R0 and a >= A_MIN) and floor(a * 255 + 0.5) or 0 end rows[j] = string.char(table.unpack(row, 1, HALO_N)) end HALO_M, halo_q = table.concat(rows), q return HALO_M end local function draw_moon_at(cx, ph, lit) local c, waxing = cos(PI2 * ph), ph < 0.5 gfx.blend_mask(halo_mask(cx, lit), HALO[1], HALO[2], HALO[3], HALO_X, HALO_Y, HALO_N, HALO_N, HALO_N, HALO_N, 1.0) for dy = -MOON_R, MOON_R do local xa, xb = lit_span(dy, c, waxing) if xa and xb - xa > 0.05 then span_aa(MOON_Y + dy, cx + xa, cx + xb, LIT[1], LIT[2], LIT[3]) end end for k = 1, 3 do local m = MARES[k] local mx, my, mr = m[1], m[2], m[3] for dy = -mr, mr do local xa, xb = lit_span(my + dy, c, waxing) if xa then local hw = sqrt(mr * mr - dy * dy) + 0.5 local a, b = mx - hw, mx + hw if a < xa then a = xa end if b > xb then b = xb end if b - a > 0.05 then span_aa(MOON_Y + my + dy, cx + a, cx + b, MARE[1], MARE[2], MARE[3]) end end end end end local SKYS, sky_key, sky_q = nil, nil, -1 local moon_on, moon_ph, moon_lit = false, 0.0, 0.0 local function build_sky(q) local sh = q * 0.25 local gt = sky_h - GLOW_N rect(0, 0, W, gt, SKY[1], SKY[2], SKY[3]) for y = gt, sky_h - 1 do rect(0, y, W, 1, mix(SKY, HOR, (y - gt + 2) / (GLOW_N + 1))) end for x = 0, W - 1 do local u = PI2 * (x + 0.5 - sh) / W local yc = BAND_Y + BAND_A * sin(u + BAND_PH) local k = VEIL_K * (0.62 + 0.38 * sin(3 * u + 0.7)) * (0.78 + 0.14 * sin(11 * u + 0.3) + 0.10 * sin(23 * u + 2.1)) local vr, vg, vb = mix(VEIL_A, VEIL_B, 0.5 + 0.5 * sin(2 * u + 1.9)) local hw = VEIL_HW * (0.86 + 0.14 * sin(17 * u + 1.0)) local y1 = floor(yc + hw) if y1 > sky_h - 1 then y1 = sky_h - 1 end for y = ceil(yc - hw), y1 do local a = 1 - abs(y + 0.5 - yc) / hw if k * a >= 0.09 then blend(x, y, vr, vg, vb, k * a) end end end if moon_on then local cx = MOON_X + 0.5 + sh draw_moon_at(cx, moon_ph, moon_lit) end SKYS, sky_q = nil, q SKYS = gfx.snapshot(0, 0, W, sky_h) end local LAND = nil local function hill(x) return floor(LAND_TOP + 3.0 * sin(x * 0.09) + 2.0 * sin(x * 0.031 + 1.2) + 0.5) end local CAB_X, CAB_W = 20, 9 local cab_base = H for x = CAB_X, CAB_X + CAB_W - 1 do local h = hill(x); if h < cab_base then cab_base = h end end local function tree(cx, base, h) for i = 0, h - 1 do local t = i / (h - 1) local w = floor(h * 0.40 * t * t + 0.7) rect(cx - w, base - h + i, 2 * w + 1, 1, 0, 0, 0) end rect(cx, base, 1, 2, 0, 0, 0) end local function build_land() rect(0, LAND_Y0, W, H - LAND_Y0, KEY[1], KEY[2], KEY[3]) for x = 0, W - 1 do local r = floor(44.5 + 2.5 * sin(x * 0.13 + 0.4) + 1.6 * sin(x * 0.05 + 2.0)) rect(x, r, 1, H - r, RIDGE_C[1], RIDGE_C[2], RIDGE_C[3]) local h = hill(x) rect(x, h, 1, H - h, 0, 0, 0) rect(x, h, 1, 1, CREST[1], CREST[2], CREST[3]) blend(x, h + 1, CREST[1], CREST[2], CREST[3], 0.45) end local bx, bw, base = CAB_X, CAB_W, cab_base for y = base + 3, H - 1 do local d = y - base - 3 local pc = bx + 4 + 2.5 * sin(d * 0.45) + d * 0.5 local hw = 0.9 + d * 0.22 span_aa(y, pc - hw, pc + hw, PATH_C[1], PATH_C[2], PATH_C[3]) end tree(9, 51, 10); tree(15, 52, 7); tree(33, 54, 8); tree(44, 53, 9); tree(55, 52, 12); tree(61, 53, 8) rect(bx, base - 4, bw, 7, 0, 0, 0) rect(bx - 1, base - 5, bw + 2, 1, 0, 0, 0) rect(bx + 1, base - 6, bw - 2, 1, 0, 0, 0) rect(bx + 3, base - 7, bw - 6, 1, 0, 0, 0) rect(bx + bw - 3, base - 9, 1, 2, 0, 0, 0) LAND = gfx.snapshot(0, LAND_Y0, W, H - LAND_Y0) end local function draw_cabin(f) local base = cab_base local fl = 0.86 + 0.14 * (umod(hash32((f // 3) * 0x9E3779B1), 100) / 100) local wr, wg, wb = floor(WIN[1] * fl), floor(WIN[2] * fl), floor(WIN[3] * fl) rect(CAB_X + 2, base - 3, 2, 2, wr, wg, wb) blend(CAB_X + 2, base - 1, wr, wg, wb, 0.30); blend(CAB_X + 3, base - 1, wr, wg, wb, 0.30) local cx, cy, T = CAB_X + CAB_W - 3, base - 10, 4 * FPS for j = 0, 4 do local age = (f + j * T // 5) % T local t = age / T local x = cx + 0.5 + t * 6.0 + 0.6 * sin(age * 0.11 + j) local y = cy - t * 13.0 local a = 0.60 * (1 - t) local yi = floor(y) local fy = y - yi local xi = floor(x) bl(xi, yi, SMOKE[1], SMOKE[2], SMOKE[3], a * (1 - fy)) bl(xi, yi + 1, SMOKE[1], SMOKE[2], SMOKE[3], a * fy) end end local TWS = {} for k = 1, 64 do TWS[k] = sin(PI2 * (k - 1) / 64) end local SQ0, SQ1 = {}, {} for k = 1, 31 do local fr = k / 32 local s = fr * fr * (3 - 2 * fr) SQ0[k], SQ1[k] = sqrt(1 - s), sqrt(s) end local function draw_stars(f, n, born, mcx) for i = 1, n do local a = 1.0 if born then local ff, L = f + soff[i], slen[i] local ln = ff // L if ln ~= sn[i] then place(i, ln, f) end local t = ff - ln * L if t < FADE then a = t / FADE elseif L - t < FADE then a = (L - t) / FADE end elseif sn[i] ~= 0 then place(i, 0, f) end if a > 0.1 then local x, sp, y = sbx[i], sper[i], sy[i] if sp > 0 then x = x + (f % sp) * W / sp; if x >= W then x = x - W end end local dx = x - mcx if dx > 32 then dx = dx - W elseif dx < -32 then dx = dx + W end if not (dx > -MOON_R - 1 and dx < MOON_R + 1 and y >= MOON_Y - MOON_R and y <= MOON_Y + MOON_R) then local b = (sb0[i] + sbt[i] * TWS[(f * stwr[i] + stwp[i]) // 1 % 64 + 1]) * a local cr, cg, cb = scr[i], scg[i], scb[i] local xi = x // 1 local k = (x - xi) * 32 // 1 local xc = xi if k == 0 then blend(xi, y, cr, cg, cb, b) else local xj = xi + 1 if xj >= W then xj = 0 end local w0, w1 = b * SQ0[k], b * SQ1[k] if w0 >= A_MIN then blend(xi, y, cr, cg, cb, w0) end if w1 >= A_MIN then blend(xj, y, cr, cg, cb, w1) end if k >= 16 then xc = xj end end if smag[i] == 2 then local ba = b * 0.45 local xl, xr = xc - 1, xc + 1 if xl < 0 then xl = W - 1 end if xr >= W then xr = 0 end bl(xl, y, cr, cg, cb, ba); bl(xr, y, cr, cg, cb, ba) bl(xc, y - 1, cr, cg, cb, ba); bl(xc, y + 1, cr, cg, cb, ba) end end end end end local function draw_meteor() local ux, uy = meteor.vx * 0.8 * FPS / 30, meteor.vy * 0.8 * FPS / 30 for k = 0, 6 do blend(floor(meteor.x - ux * k + 0.5), floor(meteor.y - uy * k + 0.5), 255, 250, 225, 1.0 - k * 0.13) end end local function draw_sat() local xi = floor(sat.x) local fr = sat.x - xi local s = fr * fr * (3 - 2 * fr) bl(xi, sat.y, 225, 230, 240, 0.75 * sqrt(1 - s)) bl(xi + 1, sat.y, 225, 230, 240, 0.75 * sqrt(s)) end local CL_N, CL_R, CL_UP = 2 * CL_HW + 3, 12, 9 local function put(m, r, i, a) if r >= -CL_UP and r < CL_R - CL_UP then m[(r + CL_UP) * CL_N + i + 1] = floor(a * 255 + 0.5) end end local function cloud_masks(q) local sub, top, bot = q * 0.25, cloud.top, cloud.bot local body, rim, bm, rm = {}, {}, {}, {} for j = 1, CL_R do for i = 1, CL_N do bm[(j - 1) * CL_N + i], rm[(j - 1) * CL_N + i] = 0, 0 end end for i = 0, CL_N - 1 do local u = i - sub local ii = floor(u) local fr = u - ii local t0, t1 = top[ii], top[ii + 1] if t0 and t1 then local yt = t0 + (t1 - t0) * fr local yb = bot[ii] + (bot[ii + 1] - bot[ii]) * fr if yb - yt > 0.3 then local r0, rb = floor(yt), floor(yb) local ft, cb = yt - r0, yb - rb for r = r0 + 1, rb do put(bm, r, i, 1) end if ft < 0.15 then put(bm, r0, i, 1) elseif ft < 0.85 then put(bm, r0, i, 1 - ft) end if cb > 0.85 then put(bm, rb + 1, i, 1) elseif cb > 0.15 then put(bm, rb + 1, i, cb) end local lit = 1.0 / (1.0 + 1.5 * abs(t1 - t0)) for r = r0, rb do local fall = 1.0 - (r + 0.5 - yt) / 2.0 if fall < 0.15 then break end if fall > 1 then fall = 1 end if r == r0 then fall = fall * (1 - ft) end if lit * fall >= A_MIN then put(rm, r, i, lit * fall) end end end end end for j = 1, CL_R do local o = (j - 1) * CL_N body[j] = string.char(table.unpack(bm, o + 1, o + CL_N)) rim[j] = string.char(table.unpack(rm, o + 1, o + CL_N)) end CLM, clm_q = nil, q CLM = { table.concat(body), table.concat(rim) } end local function draw_cloud() local xi = floor(cloud.x) local q = floor((cloud.x - xi) * 4) if q ~= clm_q then cloud_masks(q) end local m, x0, y0 = CLM, xi - CL_HW - 1, cloud.y - CL_UP gfx.blend_mask(m[1], CL_BODY[1], CL_BODY[2], CL_BODY[3], x0, y0, CL_N, CL_R, CL_N, CL_R, 1.0) gfx.blend_mask(m[2], CL_RIM[1], CL_RIM[2], CL_RIM[3], x0, y0, CL_N, CL_R, CL_N, CL_R, 1.0) end local function apply() local sh = cfg.land and LAND_TOP or H local p = (DRIFT_T[cfg.drift] or DRIFT_T.slow) * FPS if sh ~= sky_h or p ~= P or cfg.born ~= born_now then sky_h, P, born_now = sh, p, cfg.born unplace() end sky_key = nil end function on_settings() if seeded then apply() end if not cfg.cloud then cloud.on = false end end local function ensure() if not seeded or frame < last_frame then sky_h = cfg.land and LAND_TOP or H P = (DRIFT_T[cfg.drift] or DRIFT_T.slow) * FPS born_now = cfg.born seed(frame) seeded, sky_key, boot = true, nil, true end last_frame = frame end function update() ensure() local f = frame if cfg.meteors then step_meteor(f) else meteor.on = false end if cfg.satellite then step_sat(f) else sat.on = false end if cfg.cloud then step_cloud(f) else cloud.on = false end end function render() ensure() local f = frame local ph, lit = moon_phase() local mon = cfg.moon and lit >= 0.06 local key = (mon and floor(ph * 64) or -1) * 2 + (cfg.land and 1 or 0) if key ~= sky_key then sky_key, moon_on, moon_ph, moon_lit = key, mon, ph, lit sky_q, halo_q = -1, -1 end local ox = ox_at(f) local xi = floor(ox) local q = floor((ox - xi) * 4) if q ~= sky_q then build_sky(q) end if cfg.land and not LAND and not boot then build_land() end gfx.blit_rgb(SKYS, xi, 0, W, sky_h) if xi > 0 then gfx.blit_rgb(SKYS, xi - W, 0, W, sky_h) end if sky_h < H then rect(0, sky_h, W, H - sky_h, 0, 0, 0) end local mcx = nil if moon_on then mcx = fmod(MOON_X + 0.5 + xi + q * 0.25, W) end if boot then boot = false else draw_stars(f, N_STARS[cfg.stars] or N_STARS.normal, cfg.born, mcx or -1000) end if cfg.satellite and sat.on then draw_sat() end if cfg.meteors and meteor.on then draw_meteor() end if cfg.cloud and cloud.on then draw_cloud() end if cfg.land and LAND then gfx.blit_rgb(LAND, 0, LAND_Y0, W, H - LAND_Y0, KEY[1], KEY[2], KEY[3]) draw_cabin(f) end end