info = { type = "image", title = "Station orbit", category = "space", author = "BRRRO", version = "1.0", license = "MIT", desc = "Space station and astronaut above Earth", api = 44, } local tr = ({ sk = { ["Orbit speed"] = "Rýchlosť obehu", ["Astronaut"] = "Astronaut" }, cs = { ["Orbit speed"] = "Rychlost oběhu", ["Astronaut"] = "Astronaut" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "speed", label = T("Orbit speed"), type = "int", min = 1, max = 5, default = 3 }, { key = "astro", label = T("Astronaut"), type = "bool", default = true }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local blit_rgb, snapshot, blit_indexed = gfx.blit_rgb, gfx.snapshot, gfx.blit_indexed local floor, sin, sqrt, max, min = math.floor, math.sin, math.sqrt, math.max, math.min local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local LIMB = 41 local LW, NW = 128, 56 local function c3(c) return c[1], c[2], c[3] end local EL, ER = {}, {} for y = LIMB, H - 1 do local d = sqrt(70 * (y - LIMB + 0.5)) EL[y], ER[y] = max(0, floor(32 - d + 0.5)), min(W, floor(32 + d + 0.5)) end local function limb_y(x) return floor(LIMB + (x + 0.5 - 32) ^ 2 / 70) end local function band(xl, xr, y, h, r, g, b, a) local il, ir = floor(xl), floor(xr) if ir <= il then return end blend_rect(il + 1, y, ir - il - 1, h, r, g, b, a) blend_rect(il, y, 1, h, r, g, b, a * (1 - (xl - il))) blend_rect(ir, y, 1, h, r, g, b, a * (xr - ir)) end local function eband(xl, xr, y, r, g, b, a) if y < LIMB or y >= H then return end xl, xr = max(xl, EL[y]), min(xr, ER[y]) if xr > xl then band(xl, xr, y, 1, r, g, b, a) end end local function panel(x, y, w, h) rect(x, y, w, h, 202, 160, 66) rect(x + 1, y + 1, w - 2, h - 2, 34, 60, 148) for gx = x + 4, x + w - 3, 3 do rect(gx, y + 1, 1, h - 2, 84, 122, 204) end for gy = y + 4, y + h - 3, 3 do rect(x + 1, gy, w - 2, 1, 84, 122, 204) end blend_rect(x + 1, y + 1, 3, h - 2, 170, 206, 255, 0.22) end local BG, PART, STAGE = nil, nil, 1 local STAGES = { function() rect(0, 0, W, H, 2, 2, 10) for i = 1, 30 do local h = hash32(i * 0x9E3779B1) local x, y = umod(h, W), umod(h >> 8, 36) if y < limb_y(x) - 4 then local v = 70 + umod(h >> 16, 150) px(x, y, v, v, min(255, v + 20)) end end for y = LIMB, H - 1 do local t = (y - LIMB) / (H - LIMB) rect(EL[y], y, ER[y] - EL[y], 1, floor(84 - 62 * t), floor(140 - 74 * t), floor(220 - 70 * t)) end for x = 0, W - 1 do local y = LIMB while y < H - 1 and not (EL[y] <= x and x < ER[y]) do y = y + 1 end px(x, y - 1, 120, 190, 255); px(x, y - 2, 60, 110, 214); px(x, y - 3, 28, 52, 130) end end, function() rect(4, 21, 56, 1, 196, 200, 212); rect(4, 22, 56, 1, 140, 146, 164); rect(4, 23, 56, 1, 88, 94, 116) for x = 6, 58, 4 do px(x, 22, 70, 74, 96) end rect(10, 19, 2, 2, 140, 146, 164); rect(10, 24, 2, 2, 140, 146, 164) rect(52, 19, 2, 2, 140, 146, 164); rect(52, 24, 2, 2, 140, 146, 164) rect(20, 18, 2, 6, 98, 104, 128); rect(42, 18, 2, 6, 98, 104, 128) rect(22, 17, 20, 1, 236, 240, 248); rect(22, 18, 20, 3, 206, 212, 228) rect(22, 21, 20, 2, 170, 178, 198); rect(22, 23, 20, 2, 112, 120, 146) for x = 25, 39, 4 do rect(x, 19, 2, 1, 250, 214, 120) end rect(29, 10, 6, 7, 214, 220, 234); rect(29, 10, 2, 7, 240, 244, 250); rect(33, 10, 2, 7, 150, 158, 182) rect(29, 9, 6, 1, 120, 128, 152) rect(29, 25, 6, 5, 186, 192, 210); rect(29, 25, 2, 5, 222, 228, 240); rect(33, 25, 2, 5, 122, 130, 156) rect(36, 6, 11, 5, 244, 246, 252); rect(36, 6, 11, 1, 255, 255, 255) for x = 39, 45, 3 do rect(x, 7, 1, 4, 168, 176, 200) end rect(42, 11, 1, 6, 150, 158, 182) px(37, 27, 200, 204, 218); px(38, 26, 200, 204, 218) panel(5, 7, 12, 13); panel(5, 25, 12, 13); panel(47, 7, 12, 13); panel(47, 25, 12, 13) BG = snapshot(0, 0, W, H) end, } local PAL = { 0, 0, 0, 236, 240, 250, 146, 154, 182, 244, 184, 64, 232, 108, 40, 40, 44, 64, 255, 246, 170 } local BODY = { "...11111...", "..1111331..", "..1111333..", "..1111331..", "...21111...", ".44111112..", ".44111112..", ".44111112..", "..4111112..", "...11.11...", "...22.22...", } local function sprite(arm_row) local rows = {} for i = 1, 11 do rows[i] = BODY[i] end rows[arm_row] = ".4411111116" return (table.concat(rows):gsub(".", function(c) return string.char(c == "." and 0 or c:byte() - 48) end)) end local POSE = { sprite(7), sprite(6), sprite(8) } local PSEQ = { 1, 1, 2, 1, 3, 3, 1, 2 } local SHAPE = { { { 0, 3, 6 }, { 1, 0, 10 }, { 2, 2, 7 } }, { { 0, 0, 8 }, { 1, 1, 6 } }, { { 0, 2, 9 }, { 1, 0, 13 }, { 2, 1, 9 }, { 3, 4, 5 } }, } local CLOUD = { { 4, 44, 1 }, { 20, 52, 3 }, { 41, 47, 2 }, { 58, 58, 3 }, { 77, 43, 2 }, { 92, 55, 1 }, { 108, 49, 2 }, { 121, 60, 1 } } local LAND = { { 30, 47, { { 0, 0, 9 }, { 1, -2, 14 }, { 2, 0, 11 }, { 3, 3, 6 } }, { 52, 104, 64 } }, { 95, 55, { { 0, 2, 8 }, { 1, 0, 13 }, { 2, 1, 9 } }, { 172, 150, 92 } }, } local CITY = { { 14, 46 }, { 19, 52 }, { 24, 48 }, { 29, 58 }, { 33, 50 }, { 38, 45 }, { 42, 55 }, { 22, 60 }, { 12, 57 }, { 36, 61 } } local function curve(y) return 6 * sin((y - LIMB) * 0.14) end local function earth(t, v0) local o = t * v0 for i = 1, #LAND do local L = LAND[i] local x = (L[1] - o) % LW local c = L[4] for k = 1, #L[3] do local r = L[3][k] for rep = -1, 0 do eband(x + r[2] + rep * LW, x + r[2] + r[3] + rep * LW, L[2] + r[1], c[1], c[2], c[3], 1) end end end for i = 1, #CLOUD do local c = CLOUD[i] local x = (c[1] - o * (1.15 + 0.12 * c[3])) % LW local sh = SHAPE[c[3]] for k = 1, #sh do local r = sh[k] local a = k == 1 and 0.9 or 0.78 for rep = -1, 0 do eband(x + r[2] + rep * LW, x + r[2] + r[3] + rep * LW, c[2] + r[1], 238, 244, 252, a) end end end for y = LIMB, H - 2, 2 do local s = floor((-(o + curve(y))) % LW) for rep = -1, 0 do local a = s + rep * LW local function seg(x0, x1, al) local xl, xr = max(a + x0, EL[y + 1]), min(a + x1, ER[y + 1]) if xr > xl then blend_rect(xl, y, xr - xl, 2, 4, 8, 28, al) end end seg(0, 3, 0.3); seg(3, 6, 0.6); seg(6, NW - 6, 0.84); seg(NW - 6, NW - 3, 0.6); seg(NW - 3, NW, 0.3) end end for i = 1, #CITY do local c = CITY[i] local x = floor((c[1] - o) % LW) if x >= 64 then x = x - LW end if x >= 0 and c[2] >= LIMB and x >= EL[c[2]] and x < ER[c[2]] then blend_rect(x, c[2], 1, 1, 255, 214, 120, 0.55 + 0.3 * sin(t * 2 + i * 1.7)) end end end local function lights(t) local ph = t % 2 if ph < 0.35 then blend_rect(4, 20, 1, 1, 255, 40, 40, 1) end if ph >= 1 and ph < 1.35 then blend_rect(59, 20, 1, 1, 60, 255, 90, 1) end if t % 1.5 < 0.12 then rect(31, 8, 2, 1, 255, 255, 255) end local a = floor(t * 2) % 4 local corners = { { 5, 7 }, { 58, 37 }, { 58, 7 }, { 5, 37 } } local p = corners[a + 1] blend_rect(p[1], p[2], 1, 1, 255, 190, 60, 1) end local function satellite(t) local P = 30 local u = (t % P) / 8 if u > 1 then return end local x = 72 - 80 * u band(x - 3.5, x - 1.5, 4, 1, 90, 150, 255, 1) band(x + 1.5, x + 3.5, 4, 1, 90, 150, 255, 1) band(x - 1.5, x + 1.5, 4, 1, 210, 214, 224, 1) band(x - 1.5, x + 1.5, 5, 1, 150, 124, 70, 1) if t % 2 < 0.15 then blend_rect(floor(x), 3, 1, 1, 255, 255, 255, 1) end end local function tether(t) local sag = 3 + 0.8 * sin(t * 0.9) for i = 0, 14 do local k = i / 14 px(34 + floor(6 * k + 0.5), 25 + floor(6 * k + sag * sin(3.1416 * k) + 0.5), 210, 214, 226) end end function render() if not BG then if STAGE > 1 then blit_rgb(PART, 0, 0, W, H) end STAGES[STAGE]() STAGE = STAGE + 1 if not BG then PART = snapshot(0, 0, W, H); gfx.ready(false) end return end local t = frame / FPS blit_rgb(BG, 0, 0, W, H) earth(t, 0.9 * (cfg.speed or 3) + 0.6) satellite(t) lights(t) if cfg.astro ~= false then tether(t) blit_indexed(POSE[PSEQ[(frame // 20) % #PSEQ + 1]], PAL, 39, 26, 11, 11, 11, 11, true) end end