info = { type = "image", title = "Canyon haze", category = "nature", author = "BRRRO", version = "1.0", license = "MIT", desc = "Hazy red canyon, a lone pilgrim on a rock", api = 44, } local tr = ({ sk = { ["Dust"] = "Prach", ["Sun glow breathes"] = "Slnko dýcha" }, cs = { ["Dust"] = "Prach", ["Sun glow breathes"] = "Slunce dýchá" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "dust", label = T("Dust"), type = "int", min = 0, max = 16, default = 8 }, { key = "breath", label = T("Sun glow breathes"), type = "bool", default = true }, } local rect, blend, blend_rect = gfx.rect, gfx.blend, gfx.blend_rect local floor, sin, sqrt = math.floor, math.sin, math.sqrt local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local TAU = 6.28318 local SKY_T, SKY_B = { 196, 112, 78 }, { 242, 190, 144 } local GLOW = { 255, 228, 184 } local FAR_T, FAR_B = { 178, 104, 86 }, { 204, 130, 100 } local FAR_RIM = { 206, 136, 108 } local SAND_T, SAND_B = { 224, 120, 50 }, { 178, 76, 30 } local SUNX, SUNY = 13, 11 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 function C(r, g, b) return floor(r + 0.5), floor(g + 0.5), floor(b + 0.5) end local function disc(cx, cy, r, cr, cg, cb, a) for y = -floor(r), floor(r) do local hw = floor(sqrt(r * r - y * y) + 0.5) if a then blend_rect(cx - hw, cy + y, 2 * hw + 1, 1, cr, cg, cb, a) else rect(cx - hw, cy + y, 2 * hw + 1, 1, cr, cg, cb) end end end local function st_sky() for y = 0, 43 do rect(0, y, W, 1, mix(SKY_T, SKY_B, y / 43)) end for r = 13, 5, -1 do disc(SUNX, SUNY, r, GLOW[1], GLOW[2], GLOW[3], 0.05) end disc(SUNX, SUNY, 4.6, 252, 226, 180) disc(SUNX, SUNY, 3.6, 255, 243, 214) end local FAR = { { 0, 9, 36 }, { 9, 15, 33 }, { 15, 26, 35 }, { 26, 31, 32 }, { 31, 44, 34 }, { 44, 52, 38 }, { 52, 64, 33 } } local MID = { { 13, 28, 39 }, { 28, 37, 42 }, { 51, 64, 36 } } local function st_mesas() for _, s in ipairs(FAR) do for y = s[3], 43 do rect(s[1], y, s[2] - s[1], 1, mix(FAR_T, FAR_B, (y - 31) / 12)) end rect(s[1], s[3], s[2] - s[1], 1, FAR_RIM[1], FAR_RIM[2], FAR_RIM[3]) end for _, m in ipairs(MID) do local x0, w = m[1], m[2] - m[1] for y = m[3], 46 do local k = (y - m[3]) % 4 == 3 and 14 or 0 local d = (y - m[3]) * 1.2 rect(x0, y, w, 1, C(150 - k - d, 76 - k * 0.6 - d * 0.5, 54 - k * 0.5 - d * 0.4)) rect(x0, y, 2, 1, C(172 - k - d, 92 - k * 0.6 - d * 0.5, 64 - k * 0.5)) rect(x0 + w - 3, y, 3, 1, C(112 - k - d * 0.5, 54 - k * 0.5, 42 - k * 0.4)) end rect(x0, m[3], w, 1, 190, 108, 72) end for y = 36, 45 do blend_rect(0, y, W, 1, 238, 172, 130, 0.04 + 0.022 * (y - 36)) end end local function st_sand() for y = 45, H - 1 do rect(0, y, W, 1, mix(SAND_T, SAND_B, (y - 45) / 18)) end for k = 0, 4 do rect(30 + k * 3, 50 + k, 3, 1, 150, 62, 24) blend_rect(29 + k * 3, 49 + k, 3, 1, 240, 146, 70, 0.5) rect(40 + k * 3, 56 + (k > 2 and 1 or 0) + k // 2, 3, 1, 150, 62, 24) end rect(26, 60, 4, 1, 150, 62, 24); rect(54, 52, 5, 1, 152, 64, 26); rect(33, 62, 5, 1, 150, 62, 24) blend_rect(13, 46, 15, 2, 90, 36, 26, 0.45); blend_rect(51, 46, 13, 2, 90, 36, 26, 0.4) end local CLIFF = { 6, 7, 9, 11, 12, 14, 16, 17, 17, 19, 18, 19, 20, 20, 21, 21, 20, 20 } local function st_cliff() for i = 1, #CLIFF do local y, xm = 45 + i, CLIFF[i] local strata = ((y - 46) % 5 == 4) and 12 or 0 for x = 0, xm - 1, 2 do local t = (x / xm) ^ 1.4 local wdt = math.min(2, xm - x) rect(x, y, wdt, 1, C(168 - 100 * t - strata, 80 - 52 * t - strata * 0.6, 56 - 30 * t - strata * 0.5)) end if (y - 46) % 5 == 0 then rect(0, y, xm - 3, 1, 190, 100, 70) end end local ROCK = { { 44, 5 }, { 43, 7 }, { 42, 9 }, { 41, 11 }, { 40, 13 } } for i, r in ipairs(ROCK) do local y = 41 + i rect(r[1], y, r[2], 1, 150, 74, 50) rect(r[1], y, 2, 1, 186, 98, 64) rect(r[1] + r[2] - 3, y, 3, 1, 96, 44, 36) end rect(44, 42, 5, 1, 206, 118, 80) local CL = { 3, 3, 4, 4, 5, 5 } for i, w in ipairs(CL) do rect(46 - w // 2, 34 + i, w, 1, 62, 26, 22) rect(46 - w // 2, 34 + i, 1, 1, 104, 48, 36) end rect(45, 33, 3, 2, 62, 26, 22); rect(45, 33, 1, 1, 104, 48, 36) rect(49, 32, 1, 10, 88, 48, 30) end local STAGES = { st_sky, st_mesas, st_sand, st_cliff } local stage, BG = 0, nil local DX, DY, DV, DA = {}, {}, {}, {} for i = 1, 16 do local h = hash32(i * 0x9E3779B1) DX[i], DY[i] = umod(h, W + 8), 40 + umod(h >> 8, 22) DV[i] = 5 + umod(h >> 16, 80) / 10 DA[i] = 0.22 + umod(h >> 24, 20) / 100 end local function draw_dust(n, t) for i = 1, n do local x = (DX[i] + DV[i] * t) % (W + 8) - 4 local ix = floor(x) local f, a, y = x - ix, DA[i], DY[i] blend(ix, y, 240, 186, 134, a * (1 - f)) blend(ix + 1, y, 240, 186, 134, a) blend(ix + 2, y, 240, 186, 134, a * f) blend(ix - 1, y, 240, 186, 134, a * 0.3 * (1 - f)) end end function render() if stage < #STAGES then if BG then gfx.blit_rgb(BG, 0, 0, W, H) else gfx.clear(SKY_B[1], SKY_B[2], SKY_B[3]) end stage = stage + 1 STAGES[stage]() BG = gfx.snapshot(0, 0, W, H) if stage < #STAGES then gfx.ready(false) end return end gfx.blit_rgb(BG, 0, 0, W, H) local t = frame / FPS if cfg.breath ~= false then local b = 0.5 + 0.5 * sin(t * TAU / 7) for k = 1, 3 do disc(SUNX, SUNY, 3 + 3 * k, GLOW[1], GLOW[2], GLOW[3], 0.015 + 0.04 * b) end disc(SUNX, SUNY, 3.6, C(255, 243 + 12 * b, 214 + 30 * b)) end draw_dust(cfg.dust or 8, t) end