info = { type = "image", title = "Summer peak", category = "nature", author = "BRRRO", version = "1.0", license = "MIT", desc = "Snowy peak over a summer meadow, cloud shadows", api = 44, } local tr = ({ sk = { ["Clouds"] = "Oblaky", ["Wind"] = "Vietor" }, cs = { ["Clouds"] = "Oblaka", ["Wind"] = "VĂ­tr" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "clouds", label = T("Clouds"), type = "int", min = 0, max = 4, default = 3 }, { key = "wind", label = T("Wind"), type = "int", min = 1, max = 5, default = 3 }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local blit_rgb, snapshot = gfx.blit_rgb, gfx.snapshot local floor, sin, max, min = math.floor, math.sin, math.max, math.min local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local function vn(i, seed) return (hash32(i * 0x9E3779B1 + seed) & 0x7FFF) / 32767 end local function noise(x, seed) local i = floor(x) local f = x - i f = f * f * (3 - 2 * f) return vn(i, seed) * (1 - f) + vn(i + 1, seed) * f end local function poly(p, x) for i = 1, #p - 2, 2 do if x <= p[i + 2] then local t = (x - p[i]) / (p[i + 2] - p[i]) return p[i + 1] + (p[i + 3] - p[i + 1]) * t end end return p[#p] end local function rgb(r, g, b) return floor(r + 0.5), floor(g + 0.5), floor(b + 0.5) end local function mix(a, b, t) return a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t, a[3] + (b[3] - a[3]) * t end local function c3(c) return c[1], c[2], c[3] end local SKY_T, SKY_H = { 46, 104, 214 }, { 182, 218, 248 } local FARC = { 146, 174, 222 } local SNOW_L, SNOW_S = { 252, 252, 255 }, { 150, 172, 224 } local ROCK_L, ROCK_S = { 178, 162, 150 }, { 98, 98, 130 } local FOR_L, FOR_S = { 74, 138, 72 }, { 36, 86, 66 } local RIDGE_P = { 0, 38, 4, 31, 8, 24, 12, 17, 16, 12, 19, 9, 21, 7, 24, 10, 28, 15, 32, 20, 37, 25, 43, 29, 50, 33, 58, 36, 64, 38 } local RIDGE, SNOWY, FOREST, LIT, FARY = {}, {}, {}, {}, {} for x = 0, W - 1 do RIDGE[x] = floor(poly(RIDGE_P, x) + (noise(x / 2.4, 17) - 0.5) * 2.6 + (noise(x / 1.1, 5) - 0.5) * 1.1 + 0.5) FARY[x] = floor(33 + 3 * sin(x * 0.19) + 2 * sin(x * 0.41 + 1) + 0.5) end for x = 0, W - 1 do local s = (RIDGE[min(x + 3, W - 1)] - RIDGE[max(x - 3, 0)]) / 6 LIT[x] = 0.5 + 0.5 * max(-1, min(1, 0.6 * s + 0.045 * (x - 21))) SNOWY[x] = 24 + noise(x / 2.1, 29) * 8 - (x > 30 and (x - 30) * 0.15 or 0) FOREST[x] = 33 + noise(x / 3.3, 61) * 5 + (x > 40 and (x - 40) * 0.25 or 0) end local XL, XR = {}, {} for y = 0, H - 1 do XL[y], XR[y] = 1, 0 for x = 0, W - 1 do if min(RIDGE[x], FARY[x]) <= y then if XR[y] < XL[y] then XL[y] = x end XR[y] = x end end end local BG, PART, STAGE = nil, nil, 1 local GLX, GLY, GLP = {}, {}, {} local function sky() for y = 0, 43 do rect(0, y, W, 1, rgb(mix(SKY_T, SKY_H, (y / 43) ^ 1.15))) end rect(0, 44, W, H - 44, c3(SKY_H)) for x = 0, W - 1 do rect(x, FARY[x], 1, 44 - FARY[x], c3(FARC)) end end local function mtn(x0, x1) for x = x0, x1 do local r, lit, sl, fl = RIDGE[x], LIT[x], SNOWY[x], FOREST[x] local sg = lit > 0.5 and 1 or -1 for y = r, 43 do local d = y - r local t = max(0, min(1, lit + (noise((x + d * 0.7 * sg) / 2.3, 41) - 0.5) * 0.9)) local yy = y + (hash32(x * 31 + y * 17) & 7) * 0.5 - 1.5 if yy < sl then px(x, y, rgb(mix(SNOW_S, SNOW_L, t))) elseif yy < fl then local k = (hash32(x * 13 + y * 7) & 7) / 40 px(x, y, rgb(mix(ROCK_S, ROCK_L, max(0, min(1, t + k - 0.1))))) else local k = noise(x / 1.3 + y * 0.9, 77) * 0.5 px(x, y, rgb(mix(FOR_S, FOR_L, max(0, min(1, t * 0.7 + k - 0.1))))) end end end end local function meadow() for y = 44, H - 1 do local t = (y - 44) / 19 if t < 0.4 then rect(0, y, W, 1, rgb(mix({ 50, 112, 66 }, { 84, 160, 56 }, t / 0.4))) else rect(0, y, W, 1, rgb(mix({ 84, 160, 56 }, { 58, 134, 40 }, (t - 0.4) / 0.6))) end end for _, y in ipairs({ 47, 51, 56 }) do blend_rect(0, y, W, 2, 230, 236, 120, 0.1) end for i = 1, 70 do local h = hash32(i * 0x85EBCA6B) local x, y = umod(h, W), 45 + umod(h >> 8, 14) local k = umod(h >> 16, 4) if k == 0 then px(x, y, 150, 204, 76) elseif k == 1 then px(x, y, 44, 110, 40) elseif k == 2 then px(x, y, 236, 236, 244) else px(x, y, 244, 206, 70) end end end local FL = { { 6, 52, 1 }, { 27, 55, 1 }, { 49, 51, 1 }, { 58, 56, 1 }, { 14, 58, 1 }, { 3, 57, 2 }, { 20, 53, 2 }, { 36, 57, 2 }, { 44, 54, 2 }, { 60, 52, 2 }, { 11, 54, 3 }, { 31, 52, 3 }, { 54, 57, 3 }, { 23, 59, 3 }, } local function blades(layer, x0, x1, hmin, hspan, tip, light, mid) for x = x0, x1 do local h = hash32(x * 0x2545F491 + layer) local ht = hmin + umod(h, hspan) local lean = umod(h >> 8, 3) - 1 local top = H - ht px(x + lean, top, c3(tip)) rect(x, top + 1, 1, 2, c3(light)) rect(x, top + 3, 1, ht - 3, c3(mid)) end end local function flowers() for _, f in ipairs(FL) do local x, y, k = f[1], f[2], f[3] rect(x, y + 2, 1, H - y - 2, 40, 104, 40) if k == 1 then rect(x - 1, y + 1, 3, 1, 252, 252, 255); rect(x, y, 1, 3, 252, 252, 255); px(x, y + 1, 250, 200, 50) elseif k == 2 then rect(x - 1, y, 3, 2, 252, 214, 60); px(x, y - 1, 252, 214, 60); px(x, y + 1, 214, 150, 30) else rect(x, y, 2, 2, 130, 110, 220); px(x - 1, y + 1, 96, 80, 190); px(x + 1, y - 1, 170, 152, 240) end end end local STAGES = { sky, function() mtn(0, 5) end, function() mtn(6, 11) end, function() mtn(12, 17) end, function() mtn(18, 23) end, function() mtn(24, 29) end, function() mtn(30, 35) end, function() mtn(36, 41) end, function() mtn(42, 47) end, function() mtn(48, 53) end, function() mtn(54, 59) end, function() mtn(60, 63) end, meadow, function() blades(1, 0, W - 1, 4, 6, { 150, 214, 80 }, { 96, 176, 56 }, { 50, 122, 40 }) end, flowers, function() blades(2, 0, W - 1, 3, 5, { 100, 184, 62 }, { 56, 140, 46 }, { 28, 92, 36 }) end, function() local k, i = 0, 0 while k < 6 and i < 300 do i = i + 1 local h = hash32(i * 0xC2B2AE35) local x, y = 22 + umod(h, 22), 8 + umod(h >> 8, 16) if y > RIDGE[x] + 1 and y < SNOWY[x] - 2 then k = k + 1 GLX[k], GLY[k], GLP[k] = x, y, umod(h >> 16, 90) end end end, } local function build() if STAGE > 1 then blit_rgb(PART, 0, 0, W, H) end STAGES[STAGE]() PART = snapshot(0, 0, W, H) if STAGE == #STAGES then BG = PART end STAGE = STAGE + 1 end local CLOUDS = { { 5, 22, 1.0, 5 }, { 12, 16, 1.4, 30 }, { 18, 20, 0.8, 50 }, { 9, 12, 1.2, 58 } } local NC, WIND = 3, 3 function on_settings() NC, WIND = cfg.clouds or 3, cfg.wind or 3 end local function soft_row(xl, xr, y, a, r, g, b) local il, ir = floor(xl), floor(xr) if ir <= il then return end if ir - il > 1 then blend_rect(il + 1, y, ir - il - 1, 1, r, g, b, a) end blend_rect(il, y, 1, 1, r, g, b, a * (1 - (xl - il))) blend_rect(ir, y, 1, 1, r, g, b, a * (xr - ir)) end function render() if not BG then build(); if not BG then gfx.ready(false) end return end blit_rgb(BG, 0, 0, W, H) local t = frame / FPS * (0.5 + 0.35 * WIND) local sh = {} for i = 1, NC do local c = CLOUDS[i] local L = c[2] local x = (c[4] + t * c[3]) % (W + 2 * L) - L soft_row(x + L * 0.25, x + L * 0.75, c[1], 0.8, 255, 255, 255) soft_row(x + L * 0.05, x + L * 0.95, c[1] + 1, 0.9, 255, 255, 255) soft_row(x, x + L, c[1] + 2, 0.9, 250, 252, 255) soft_row(x + L * 0.1, x + L * 0.9, c[1] + 3, 0.7, 206, 220, 244) sh[i] = { x, L, 20 + c[1] * 1.5 } end for i = 1, NC do local s = sh[i] local L = s[2] local cx = s[1] + L / 2 - 5 for k = -2, 2 do local y = floor(s[3]) + k local hw = L * 0.5 * (1 - (k / 2.6) ^ 2) ^ 0.5 local xl, xr = max(cx - hw, XL[y] or 0), min(cx + hw, (XR[y] or -1) + 1) soft_row(xl, xr, y, 0.44 - 0.08 * math.abs(k), 20, 36, 92) end end for k = 1, #GLX do if (frame + GLP[k] * 3) % 120 < 6 then px(GLX[k], GLY[k], 255, 255, 255) end end end