info = { type = "image", title = "Pastel peaks", category = "nature", author = "BRRRO", version = "1.0", license = "MIT", desc = "Flat pastel mountains, mist and a calm lake", api = 44, } local tr = ({ sk = { ["Palette"] = "Paleta", ["Rose"] = "Ružová", ["Mint"] = "Mätová", ["Lavender"] = "Levanduľová", ["Mist"] = "Hmla", ["Drift speed"] = "Rýchlosť driftu" }, cs = { ["Palette"] = "Paleta", ["Rose"] = "Růžová", ["Mint"] = "Mátová", ["Lavender"] = "Levandulová", ["Mist"] = "Mlha", ["Drift speed"] = "Rychlost driftu" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "palette", label = T("Palette"), type = "int", default = "rose", opts = { keys = { "rose", "mint", "lavender" }, T("Rose"), T("Mint"), T("Lavender") } }, { key = "mist", label = T("Mist"), type = "int", min = 0, max = 3, default = 2 }, { key = "speed", label = T("Drift speed"), type = "int", min = 1, max = 5, default = 3 }, } local rect, blend_rect, blend = gfx.rect, gfx.blend_rect, gfx.blend local blit_rgb, snapshot = gfx.blit_rgb, gfx.snapshot local floor, sin, max, min, abs = math.floor, math.sin, math.max, math.min, math.abs local W, H, FPS = gfx.W, gfx.H, gfx.FPS local SHORE = 44 local PALS = { rose = { skyT = { 252, 204, 196 }, skyH = { 255, 234, 216 }, sun = { 255, 248, 226 }, L = { { { 234, 172, 180 }, { 218, 152, 168 } }, { { 210, 136, 158 }, { 188, 114, 142 } }, { { 188, 106, 136 }, { 156, 80, 114 } }, { { 140, 70, 104 }, { 116, 54, 90 } } }, lakeT = { 246, 200, 202 }, lakeB = { 210, 150, 178 }, cloud = { 255, 248, 244 }, ink = { 120, 70, 104 }, }, mint = { skyT = { 204, 238, 226 }, skyH = { 242, 252, 238 }, sun = { 255, 250, 226 }, L = { { { 176, 226, 208 }, { 154, 208, 194 } }, { { 124, 200, 182 }, { 100, 176, 164 } }, { { 74, 160, 148 }, { 52, 134, 128 } }, { { 38, 110, 112 }, { 28, 90, 98 } } }, lakeT = { 194, 240, 228 }, lakeB = { 122, 202, 198 }, cloud = { 252, 255, 250 }, ink = { 42, 96, 104 }, }, lavender = { skyT = { 214, 206, 244 }, skyH = { 248, 230, 242 }, sun = { 255, 242, 228 }, L = { { { 194, 180, 232 }, { 174, 160, 218 } }, { { 152, 134, 208 }, { 130, 112, 188 } }, { { 110, 90, 172 }, { 86, 68, 148 } }, { { 72, 54, 128 }, { 58, 44, 108 } } }, lakeT = { 224, 210, 246 }, lakeB = { 162, 144, 210 }, cloud = { 255, 250, 252 }, ink = { 84, 64, 130 }, }, } local PAL = PALS.rose local RIDGES = { { { 52, 24, 0.9 }, { 30, 17, 0.7 }, { 2, 19, 0.8 } }, { { 40, 17, 0.8 }, { 6, 16, 0.7 }, { 62, 15, 0.7 } }, { { 20, 32, 1.0 }, { 47, 12, 0.9 } }, { { 60, 9, 0.55 }, { 0, 7, 0.5 } }, } local TOP, SIDE = {}, {} for l = 1, 4 do TOP[l], SIDE[l] = {}, {} for x = 0, W - 1 do local best, bp = 0, 1 for i, p in ipairs(RIDGES[l]) do local h = p[2] - p[3] * abs(x - p[1]) if h > best then best, bp = h, i end end TOP[l][x] = SHORE - floor(best + 0.8 * sin(x * 0.45 + l) + 0.5) SIDE[l][x] = x >= RIDGES[l][bp][1] and 1 or 2 end end local function mix(a, b, t) return floor(a + (b - a) * t + 0.5) end local function mix3(a, b, t) return mix(a[1], b[1], t), mix(a[2], b[2], t), mix(a[3], b[3], t) end local function disc(cx, cy, r, c, a) for dy = -r, r do local w = floor(math.sqrt(r * r - dy * dy) + 0.5) if a then blend_rect(cx - w, cy + dy, 2 * w + 1, 1, c[1], c[2], c[3], a) else rect(cx - w, cy + dy, 2 * w + 1, 1, c[1], c[2], c[3]) end end end local function fog(y0, rows) local s = PAL.skyH for i = 1, #rows do blend_rect(0, y0 + i - 1, W, 1, s[1], s[2], s[3], rows[i]) end end local function layer(l) local pal = PAL.L[l] for x = 0, W - 1 do local c = pal[SIDE[l][x]] local top = TOP[l][x] rect(x, top, 1, SHORE - top, c[1], c[2], c[3]) end end local function reflect(l) local pal, lk = PAL.L[l], PAL.lakeT for x = 0, W - 1 do local c = pal[SIDE[l][x]] local h = min(SHORE - TOP[l][x], H - SHORE) if h > 0 then rect(x, SHORE, 1, h, mix3(c, lk, 0.5)) end end end local SUNX, SUNY = 46, 14 local STAGES = { function() for y = 0, SHORE - 1 do rect(0, y, W, 1, mix3(PAL.skyT, PAL.skyH, y / (SHORE - 1))) end disc(SUNX, SUNY, 12, PAL.sun, 0.12); disc(SUNX, SUNY, 9, PAL.sun, 0.18); disc(SUNX, SUNY, 6, PAL.sun) layer(1) fog(27, { 0.15, 0.3, 0.45, 0.3, 0.15 }) layer(2) end, function() fog(30, { 0.15, 0.3, 0.4, 0.3, 0.15 }) layer(3) fog(37, { 0.12, 0.24, 0.36, 0.36, 0.24, 0.12 }) layer(4) end, function() for y = SHORE, H - 1 do rect(0, y, W, 1, mix3(PAL.lakeT, PAL.lakeB, (y - SHORE) / (H - 1 - SHORE))) end for l = 1, 4 do reflect(l) end end, } local STAGE, PART, BG = 1, nil, nil function on_settings() PAL = PALS[cfg.palette] or PALS.rose STAGE, PART, BG = 1, nil, nil end local function frow(x, y, w, c, a) local ix = floor(x) local f = x - ix blend_rect(ix + 1, y, w - 1, 1, c[1], c[2], c[3], a) blend_rect(ix, y, 1, 1, c[1], c[2], c[3], a * (1 - f)) blend_rect(ix + w, y, 1, 1, c[1], c[2], c[3], a * f) end local function fpx(x, y, c, a) local ix = floor(x) local f = x - ix blend(ix, y, c[1], c[2], c[3], a * (1 - f)) blend(ix + 1, y, c[1], c[2], c[3], a * f) end local CLOUDS = { { 5, 2.2, 6, 18 }, { 11, 1.4, 52, 24 }, { 20, 1.0, 30, 14 } } local WISPS = { { 31, 1.1, 10, 26 }, { 40, -0.8, 40, 30 }, { 25, 0.7, 60, 22 } } local function draw_bird(t) local x = 76 - (t * 3.2 + 20) % 100 local y = 17 + 2 * sin(t * 0.8) local iy = floor(y + 0.5) local up = (t * 2.8) % 1 < 0.5 local k = PAL.ink fpx(x - 2, iy + (up and -1 or 1), k, 1); fpx(x - 1, iy, k, 1); fpx(x, iy, k, 1) fpx(x + 1, iy, k, 1); fpx(x + 2, iy + (up and -1 or 1), k, 1) end function render() if STAGE <= #STAGES then if PART then blit_rgb(PART, 0, 0, W, H) end STAGES[STAGE]() PART = snapshot(0, 0, W, H) STAGE = STAGE + 1 if STAGE > #STAGES then BG, PART = PART, nil end gfx.ready(false) return end blit_rgb(BG, 0, 0, W, H) local t = frame / FPS * (0.4 + 0.2 * (cfg.speed or 3)) local s = PAL.sun for y = SHORE + 1, H - 1, 1 do if (y + floor(t * 2)) % 3 ~= 0 then local w = 6 * (1 - (y - SHORE) / (H - SHORE)) + 1.5 * sin(t * 1.3 + y * 0.9) + 1 if w > 1 then blend_rect(floor(SUNX - w / 2 + 0.5), y, floor(w), 1, s[1], s[2], s[3], 0.5) end end end local lb = PAL.skyH for k = 0, 5 do local y = SHORE + 3 + k * 3 frow((t * (1.2 + k * 0.15) + k * 17) % 90 - 20, y, 9 + k % 3 * 3, lb, 0.22) end local cl = PAL.cloud for i = 1, #CLOUDS do local c = CLOUDS[i] local x = (c[3] + t * c[2]) % (W + 30) - 24 local w = c[4] frow(x + 3, c[1], w - 6, cl, 0.85); frow(x, c[1] + 1, w, cl, 0.85); frow(x + 2, c[1] + 2, w - 4, cl, 0.7) end for i = 1, cfg.mist or 2 do local m = WISPS[i] local x = (m[3] + t * m[2]) % (W + 40) - 30 frow(x + 4, m[1], m[4] - 8, PAL.skyH, 0.28); frow(x, m[1] + 1, m[4], PAL.skyH, 0.4) frow(x + 3, m[1] + 2, m[4] - 6, PAL.skyH, 0.22) end draw_bird(t) end