info = { type = "image", title = "Paraglider", category = "nature", author = "BRRRO", version = "1.0", license = "MIT", desc = "A paraglider soars over alpine ridges", api = 33, } local tr = ({ sk = { ["Wing colour"] = "Farba krídla" }, cs = { ["Wing colour"] = "Barva křídla" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "wing", label = T("Wing colour"), type = "color", default = "#F2542D" }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local floor, ceil, sqrt, sin, cos, abs = math.floor, math.ceil, math.sqrt, math.sin, math.cos, math.abs local W, H = gfx.W, gfx.H local function span(xa, xb, y, r, g, b, a) if xb <= xa then return end a = a or 1 local ia, ib = floor(xa), floor(xb) if ia == ib then blend(ia, y, r, g, b, (xb - xa) * a) return end local s, c = ia + 1, ia + 1 - xa if c > 0.96 and a == 1 then s = ia else blend(ia, y, r, g, b, c * a) end local f = xb - ib if f > 0.04 then blend(ib, y, r, g, b, f * a) end if ib > s then if a < 1 then blend_rect(s, y, ib - s, 1, r, g, b, a) else rect(s, y, ib - s, 1, r, g, b) end end end local function oval(cx, cy, rx, ry, c, a) for y = floor(cy - ry), ceil(cy + ry) - 1 do local d = (y + 0.5 - cy) / ry if d > -1 and d < 1 then local hw = rx * sqrt(1 - d * d) span(cx - hw, cx + hw, y, c[1], c[2], c[3], a) end end end local function lin(a, b, lo, hi) if a > -1e-9 and a < 1e-9 then if b >= lo and b <= hi then return -1e9, 1e9 end return 1e9, -1e9 end local x1, x2 = (lo - b) / a, (hi - b) / a if x1 > x2 then return x2, x1 end return x1, x2 end local function capsule_rgb(x0, y0, x1, y1, rad, r, g, b, a) local dx, dy = x1 - x0, y1 - y0 local L2 = dx * dx + dy * dy local L = sqrt(L2) local ya, yb = y0, y1 if ya > yb then ya, yb = yb, ya end local r2 = rad * rad local ady = dy < 0 and -dy or dy local steep = ady > 0.35 * L local ihw, k = 0, 0 if steep then ihw, k = rad * L / ady, dx / dy end local xlo, xhi = (x0 < x1 and x0 or x1) - rad, (x0 > x1 and x0 or x1) + rad for y = floor(ya - rad), ceil(yb + rad) - 1 do local yc = y + 0.5 local lo, hi if steep and yc >= ya and yc <= yb then local xc = x0 + k * (yc - y0) lo, hi = xc - ihw, xc + ihw if lo < xlo then lo = xlo end if hi > xhi then hi = xhi end else lo, hi = 1e9, -1e9 local e = r2 - (yc - y0) * (yc - y0) if e > 0 then e = sqrt(e); lo, hi = x0 - e, x0 + e end e = r2 - (yc - y1) * (yc - y1) if e > 0 then e = sqrt(e) if x1 - e < lo then lo = x1 - e end if x1 + e > hi then hi = x1 + e end end if not steep and L > 0.01 then local pa, pb = lin(dy, -x0 * dy - (yc - y0) * dx, -rad * L, rad * L) local qa, qb = lin(dx, -x0 * dx + (yc - y0) * dy, 0, L2) if qa > pa then pa = qa end if qb < pb then pb = qb end if pb > pa then if pa < lo then lo = pa end if pb > hi then hi = pb end end end end span(lo, hi, y, r, g, b, a) end end local function capsule(x0, y0, x1, y1, rad, c, a) return capsule_rgb(x0, y0, x1, y1, rad, c[1], c[2], c[3], a) end local function lerp3(a, b, f) return floor(a[1] + (b[1] - a[1]) * f + 0.5), floor(a[2] + (b[2] - a[2]) * f + 0.5), floor(a[3] + (b[3] - a[3]) * f + 0.5) end local SKY0, SKY1 = { 58, 128, 226 }, { 200, 228, 250 } local SUN = { 255, 250, 224 } local CLOUD, CLOUD_D = { 255, 255, 255 }, { 190, 210, 238 } local FAR, FAR_S, FAR_N, FAR_NS = { 168, 192, 228 }, { 138, 164, 206 }, { 252, 254, 255 }, { 216, 228, 246 } local MIDC, MID_S, MID_N, MID_NS = { 88, 120, 160 }, { 60, 88, 130 }, { 238, 245, 255 }, { 194, 210, 234 } local NEAR, NEAR_S = { 44, 98, 88 }, { 30, 72, 72 } local EAGLE = { 44, 40, 54 } local PILOT, SUIT, HELM = { 244, 206, 176 }, { 44, 48, 74 }, { 240, 240, 240 } local WING, WING_L, WING_D = { 242, 84, 45 }, { 255, 168, 120 }, { 150, 40, 30 } local BG = nil function on_settings() local c = cfg.wing or { r = 242, g = 84, b = 45 } WING = { c.r, c.g, c.b } WING_L = { c.r + (255 - c.r) * 0.45, c.g + (255 - c.g) * 0.45, c.b + (255 - c.b) * 0.45 } WING_D = { c.r * 0.55, c.g * 0.55, c.b * 0.55 } end local function build_bg() for y = 0, 47 do rect(0, y, W, 1, lerp3(SKY0, SKY1, (y / 47) ^ 1.3)) end rect(0, 48, W, H - 48, SKY1[1], SKY1[2], SKY1[3]) local sx, sy = 11, 10 for k = 1, 3 do local r = 4 + 4 * k oval(sx, sy, r, r, SUN, 0.09) end oval(sx, sy, 3.2, 3.2, SUN) BG = gfx.snapshot(0, 0, W, H) end local function h_far(x) return 9 * (1 - abs(sin(x * 0.07 + 0.6))) + 4 * (1 - abs(sin(x * 0.19 + 2.1))) + 1.5 * sin(x * 0.41) end local function h_mid(x) return 8 * (1 - abs(sin(x * 0.11 + 1.3))) + 3.5 * (1 - abs(sin(x * 0.31 + 0.4))) + 1.2 * sin(x * 0.53) end local function h_near(x) return 4.5 * (1 - abs(sin(x * 0.17 + 2))) + 2.2 * sin(x * 0.39 + 1) + 1.0 * sin(x * 0.9) end local function ridge(hf, base, wx0, step, c, cs, sn, sns, thr) for x = 0, W - 1, step do local wx = wx0 + x + step * 0.5 local h = hf(wx) local lit = hf(wx + step) > h local col, scol = lit and c or cs, lit and sn or sns local top = base - h local ti = floor(top) local f = top - ti local sh = h > thr and (h - thr) * 0.9 or 0 local t1 = sh > 0.6 and scol or col blend_rect(x, ti, step, 1, t1[1], t1[2], t1[3], 1 - f) rect(x, ti + 1, step, H - ti - 1, col[1], col[2], col[3]) if sh > 0.6 then rect(x, ti + 1, step, floor(sh), scol[1], scol[2], scol[3]) end end end local function cloud(x, y, s) oval(x, y, 6 * s, 2.6 * s, CLOUD) oval(x - 4 * s, y + 0.6 * s, 4 * s, 2 * s, CLOUD) oval(x + 4.5 * s, y + 0.7 * s, 4 * s, 1.9 * s, CLOUD) oval(x + 0.5 * s, y + 2.3 * s, 7 * s, 0.8 * s, CLOUD_D, 0.8) end local function eagle(t) local a = t * 0.012 + 1 local x, y = 40 + 15 * cos(a), 17 + 3 * sin(t * 0.024) local dip = 0.5 + 0.5 * sin(t * 0.12) if (t // 90) % 5 ~= 0 then dip = 0.3 end capsule(x, y, x - 1.8, y - 1.0, 0.5, EAGLE); capsule(x - 1.8, y - 1.0, x - 3.8, y - 0.6 + 0.9 * dip, 0.45, EAGLE) capsule(x, y, x + 1.8, y - 1.0, 0.5, EAGLE); capsule(x + 1.8, y - 1.0, x + 3.8, y - 0.6 + 0.9 * dip, 0.45, EAGLE) capsule(x - 0.9, y + 0.3, x + 0.9, y + 0.3, 0.6, EAGLE) end local GX, GY, BANK, CB, SB = 0, 0, 0, 1, 0 local function pt(x, y, k) local c, s = CB, SB if k then c, s = cos(BANK * k), sin(BANK * k) end return GX + x * c - y * s, GY + x * s + y * c end local function glider(gx, gy, bank) GX, GY, BANK, CB, SB = gx, gy, bank, cos(bank), sin(bank) local tx0, ty0 = pt(-7.6, 2.4) local tx1, ty1 = pt(7.6, 2.4) local px_, py_ = pt(0, 9.2, 0.5) capsule(tx0, ty0, px_, py_, 0.22, SUIT, 0.55) capsule(tx1, ty1, px_, py_, 0.22, SUIT, 0.55) local bx, by = pt(0, 10.6, 0.5) local lx, ly = pt(0.3, 13.6, 0.5) capsule(bx, by, lx, ly, 0.85, SUIT) capsule(px_, py_ + 0.2, bx, by, 1.0, SUIT) local hx, hy = pt(0, 8.5, 0.5) oval(hx, hy, 1.15, 1.15, HELM) local x0, y0 = pt(-8, 0.045 * 64 - 1.0) local u0, v0 = pt(-8, 0.045 * 64 + 0.4) for i = 1, 6 do local x = -8 + 16 * i / 6 local y = 0.045 * x * x - 1.0 local x1, y1 = pt(x, y) local u1, v1 = pt(x, y + 1.4) capsule(u0, v0, u1, v1, 0.5, WING_D) capsule(x0, y0, x1, y1, 1.15, i % 2 == 0 and WING_L or WING) x0, y0, u0, v0 = x1, y1, u1, v1 end end function render() if not BG then build_bg() end if frame % 3 ~= 0 then return end gfx.blit_rgb(BG, 0, 0, W, H) local t = frame local cx1 = (t * 0.012 + 20) % 150 - 40 cloud(cx1, 18, 1.0) cloud((t * 0.02 + 90) % 150 - 40, 28, 0.8) blend_rect(floor(30 - t * 0.006 % 40), 7, 22, 1, 255, 255, 255, 0.35) ridge(h_far, 46, t * 0.012 + 10, 2, FAR, FAR_S, FAR_N, FAR_NS, 6.2) eagle(t) blend_rect(0, 43, W, 4, 255, 255, 255, 0.16) ridge(h_mid, 54, t * 0.03 + 60, 2, MIDC, MID_S, MID_N, MID_NS, 5.6) blend_rect(0, 53, W, 5, 230, 240, 250, 0.16) ridge(h_near, 62, t * 0.07 + 200, 1, NEAR, NEAR_S, NEAR, NEAR_S, 99) local prog = ((t * 0.06 + 28) % 92) / 92 local gx = -14 + 92 * prog local gy = 40 - 17 * prog + 2.2 * sin(prog * 18.85) local bank = 0.2 * cos(prog * 18.85 + 0.5) glider(gx, gy, bank) end