info = { type = "image", title = "Blimp sky", category = "other", author = "BRRRO", version = "1.0", license = "MIT", desc = "Green airship drifting through summer clouds", api = 33, } local tr = ({ sk = { ["Speed"] = "Rýchlosť", ["Clouds"] = "Oblaky", ["Shadow"] = "Tieň" }, cs = { ["Speed"] = "Rychlost", ["Clouds"] = "Oblaka", ["Shadow"] = "Stín" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "speed", label = T("Speed"), type = "int", min = 1, max = 5, default = 3 }, { key = "clouds", label = T("Clouds"), type = "int", min = 1, max = 4, default = 3 }, { key = "shadow", label = T("Shadow"), type = "bool", default = true }, } local rect, blend_rect = gfx.rect, gfx.blend_rect local floor, sqrt = math.floor, math.sqrt local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local SKY_T, SKY_B = { 34, 100, 222 }, { 150, 204, 248 } local LAYERS = { { y0 = 4, y1 = 16, l0 = 10, l1 = 8, v = 1.1, lit = { 226, 240, 252 }, sh = { 172, 202, 238 } }, { y0 = 41, y1 = 6, l0 = 16, l1 = 10, v = 2.8, lit = { 250, 252, 255 }, sh = { 188, 212, 244 } }, { y0 = 52, y1 = 7, l0 = 22, l1 = 12, v = 6.0, lit = { 255, 255, 255 }, sh = { 204, 222, 246 } }, } local PAD = 40 local CL = {} local function build_clouds() CL = {} local n = cfg.clouds or 3 for li = 1, #LAYERS do local La = LAYERS[li] for i = 1, n do local h = hash32((li * 16 + i) * 0x9E3779B1) CL[#CL + 1] = { La = La, shadow = li == 2, x0 = (i - 1) * (W + 2 * PAD) / n + umod(h, 12), y = La.y0 + umod(h >> 8, La.y1), len = La.l0 + umod(h >> 14, La.l1), } end end end local function frow(xa, xb, y, r, g, b, a) local ia, ib = floor(xa), floor(xb) if ib < ia then return end if ib == ia then blend_rect(ia, y, 1, 1, r, g, b, (xb - xa) * a) return end if ib - ia > 1 then if a >= 1 then rect(ia + 1, y, ib - ia - 1, 1, r, g, b) else blend_rect(ia + 1, y, ib - ia - 1, 1, r, g, b, a) end end blend_rect(ia, y, 1, 1, r, g, b, (1 - (xa - ia)) * a) blend_rect(ib, y, 1, 1, r, g, b, (xb - ib) * a) end local SHX, SHY, SHRX, SHRY = 0, 45, 13, 3.5 local function cloud_row(c, xa, xb, y, col) frow(xa, xb, y, col[1], col[2], col[3], 1) if c.shadow and SHX > -90 then local dy = y - SHY if dy * dy < SHRY * SHRY then local hw = SHRX * sqrt(1 - dy * dy / (SHRY * SHRY)) local a, b = math.max(xa, SHX - hw), math.min(xb, SHX + hw) if b > a then frow(a, b, y, 84, 118, 176, 0.5) end end end end local function draw_cloud(c, t) local La = c.La local x = (c.x0 + t * -La.v) % (W + 2 * PAD) - PAD local L, y = c.len, c.y cloud_row(c, x + L * 0.18, x + L * 0.6, y, La.lit) cloud_row(c, x + L * 0.04, x + L * 0.96, y + 1, La.lit) cloud_row(c, x, x + L, y + 2, La.lit) cloud_row(c, x + L * 0.06, x + L * 0.94, y + 3, La.sh) end local HULL_T, HULL_B = { 112, 214, 122 }, { 14, 82, 38 } local function vbar(x, y, h, r, g, b, a) local ix = floor(x) local fx = x - ix blend_rect(ix, y, 1, h, r, g, b, a * (1 - fx)) blend_rect(ix + 1, y, 1, h, r, g, b, a * fx) end local PROP = { 7, 4, 1, 4 } local function draw_blimp(bx, cy) for dy = -6, 5 do local hw = 15 * sqrt(1 - ((dy + 0.5) / 6) ^ 2) local t = (dy + 6) / 11 frow(bx - hw, bx + hw, cy + dy, floor(HULL_T[1] + (HULL_B[1] - HULL_T[1]) * t), floor(HULL_T[2] + (HULL_B[2] - HULL_T[2]) * t), floor(HULL_T[3] + (HULL_B[3] - HULL_T[3]) * t), 1) end frow(bx - 9, bx + 9, cy - 4, 160, 240, 160, 0.55) frow(bx - 13, bx + 13, cy - 1, 150, 232, 154, 0.35) frow(bx - 12, bx + 12, cy + 2, 8, 60, 28, 0.35) frow(bx - 17.5, bx - 14.5, cy - 8, 26, 104, 50, 1) frow(bx - 17, bx - 12, cy - 7, 26, 104, 50, 1) frow(bx - 16.5, bx - 11, cy - 6, 22, 94, 44, 1) frow(bx - 17.5, bx - 14.5, cy + 7, 16, 74, 36, 1) frow(bx - 17, bx - 12, cy + 6, 16, 74, 36, 1) vbar(bx - 4, cy + 6, 2, 60, 66, 84, 1) vbar(bx + 4, cy + 6, 2, 60, 66, 84, 1) frow(bx - 6, bx + 6, cy + 8, 176, 62, 52, 1) frow(bx - 6, bx + 6, cy + 9, 148, 44, 40, 1) frow(bx - 5.5, bx + 5.5, cy + 10, 110, 30, 32, 1) frow(bx - 4, bx + 4, cy + 9, 150, 232, 240, 0.9) local px0 = bx - 18.5 local len = PROP[(frame // 2) % 4 + 1] vbar(px0, cy - len // 2, len, 214, 230, 246, len > 1 and 0.9 or 0.5) frow(px0 - 0.5, px0 + 1, cy, 70, 80, 100, 1) end local SKY function on_settings() build_clouds() end function render() if not SKY then for y = 0, H - 1 do local t = y / (H - 1) rect(0, y, W, 1, floor(SKY_T[1] + (SKY_B[1] - SKY_T[1]) * t + 0.5), floor(SKY_T[2] + (SKY_B[2] - SKY_T[2]) * t + 0.5), floor(SKY_T[3] + (SKY_B[3] - SKY_T[3]) * t + 0.5)) end SKY = gfx.snapshot(0, 0, W, H) end gfx.blit_rgb(SKY, 0, 0, W, H) local t = frame / FPS local v = 2.0 + (cfg.speed or 3) * 1.2 local span = W + 48 + 30 local d = t * v + 40 local k = d % span local bx = -24 + k local cy = floor(33 - 9 * (k / span) + 0.5) SHX = (cfg.shadow ~= false and bx > -30 and bx < W + 30) and (bx + 3) or -99 for i = 1, #CL do if CL[i].La == LAYERS[1] then draw_cloud(CL[i], t) end end draw_blimp(bx, cy) for i = 1, #CL do if CL[i].La ~= LAYERS[1] then draw_cloud(CL[i], t) end end end