info = { type = "image", title = "Poppy brushwork", category = "nature", author = "BRRRO", version = "1.0", license = "MIT", desc = "Impressionist poppy field, wind rolls through", api = 44, } local tr = ({ sk = { ["Season"] = "Ročná doba", ["Spring"] = "Jar", ["Summer"] = "Leto" }, cs = { ["Season"] = "Roční doba", ["Spring"] = "Jaro", ["Summer"] = "Léto" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "season", label = T("Season"), type = "int", default = "summer", opts = { keys = { "spring", "summer" }, T("Spring"), T("Summer") } }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor = math.floor local hash32, umod = math.hash32, math.umod local W, H = gfx.W, gfx.H local HORIZON = 26 local SEASON = { spring = { sky = { { 96, 156, 226 }, { 206, 230, 242 } }, trees = { { 40, 96, 84 }, { 30, 74, 70 } }, under = { { 150, 196, 98 }, { 24, 78, 34 } }, haze = { 176, 212, 148 }, field = { { 64, 150, 58 }, { 104, 184, 70 }, { 40, 112, 48 }, { 150, 206, 100 }, { 30, 92, 92 } }, }, summer = { sky = { { 120, 160, 214 }, { 238, 226, 206 } }, trees = { { 58, 92, 70 }, { 44, 74, 62 } }, under = { { 214, 176, 96 }, { 122, 88, 34 } }, haze = { 226, 196, 128 }, field = { { 232, 196, 92 }, { 214, 164, 56 }, { 176, 128, 40 }, { 240, 214, 128 }, { 128, 138, 50 } }, }, } local S, PALF local BASE_STAGE, DONE = 0, 0 local STRIP = {} local N_FIELD, N_SKY, N_TREE, N_POPPY, QUOTA = 640, 80, 150, 34, 260 local function lerp3(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 function on_settings() S = SEASON[cfg.season] or SEASON.summer PALF = {} for b, k in ipairs({ 0.45, 0.15, 0 }) do PALF[b] = {} for i, c in ipairs(S.field) do local r, g, bl = lerp3(c, S.haze, k) PALF[b][i] = { r, g, bl } end end BASE_STAGE, DONE = 0, 0 end local function stroke(x, y, len, kind, r, g, b, thick) for k = 0, len - 1 do local dx, dy = k, 0 if kind == 1 then dy = -(k // 2) elseif kind == 2 then dy = -k elseif kind == 3 then dy = k // 2 else dx = 0; dy = -k end px(x + dx, y + dy, r, g, b) if thick then px(x + dx + 1, y + dy, r, g, b) end end end local function underpaint() for y = 0, HORIZON - 1 do rect(0, y, W, 1, lerp3(S.sky[1], S.sky[2], y / (HORIZON - 1))) end rect(0, HORIZON - 4, W, 6, lerp3(S.trees[2], S.haze, 0.25)) for y = HORIZON + 2, H - 1 do rect(0, y, W, 1, lerp3(S.under[1], S.under[2], (y - HORIZON - 2) / (H - HORIZON - 3))) end local sky = { { 100, 148, 210 }, { 140, 184, 232 } } for i = 1, N_SKY do local h = hash32(i * 0x9E3779B1) local c = sky[umod(h >> 20, 2) + 1] local y = umod(h >> 8, HORIZON - 6) local t = y / (HORIZON - 6) local r, g, b = lerp3(c, S.sky[2], t * 0.9) rect(umod(h, 70) - 4, y, 4 + umod(h >> 16, 3), 1, r, g, b) end for i = 1, 4 do local cx, cy = (i * 19 + 5) % 60, 3 + (i * 7) % 11 for k = 1, 14 do local h = hash32((i * 31 + k) * 0x85EBCA6B) local dx, dy = umod(h, 15) - 4, umod(h >> 8, 5) - 2 local len = 4 + umod(h >> 14, 3) rect(cx + dx, cy + dy, len, 1, 246, 246, 250) if umod(h >> 18, 3) == 0 then rect(cx + dx + 1, cy + dy + 1, len - 1, 1, 178, 192, 224) end end end for i = 1, N_TREE do local h = hash32(i * 0xC2B2AE35) local k = umod(h >> 20, 3) local r, g, b = lerp3(S.trees[k % 2 + 1], S.haze, k == 2 and 0.45 or 0) local y = HORIZON - 6 + umod(h >> 8, 9) rect(umod(h, 68) - 2, y, 2 + umod(h >> 24, 2), 2, r, g, b) end end local function poppies() for i = 1, N_POPPY do local h = hash32(i * 0x27D4EB2F) local y = 34 + umod(h >> 8, 28) local band = y < 40 and 1 or (y < 50 and 2 or 3) local w, ht = 1 + band, 1 + band // 2 + 1 local x = umod(h, 62) rect(x, y, w, ht, 214, 40, 34) rect(x + 1, y - 1, w - 1, 1, 240, 84, 60) if band > 1 then px(x + w // 2, y + ht // 2, 44, 16, 22) end end end local function build() if BASE_STAGE == 0 then underpaint() BASE_STAGE = 1 return end local first = DONE + 1 local last = math.min(first + QUOTA - 1, N_FIELD) for i = first, last do local h = hash32(i * 0x61C88647) local y = HORIZON + 2 + umod(h >> 7, H - HORIZON - 2) local d = (y - HORIZON) / (H - HORIZON) local band = d < 0.3 and 1 or (d < 0.62 and 2 or 3) local c = PALF[band][umod(h >> 17, 5) + 1] local kn = umod(h >> 13, 10) local kind = kn < 4 and 1 or (kn < 7 and 2 or (kn < 9 and 4 or 3)) stroke(umod(h, 70) - 3, y, 2 + band, kind, c[1], c[2], c[3], band == 3) end DONE = last if DONE >= N_FIELD then poppies() for g = 0, 7 do STRIP[g] = gfx.snapshot(0, g * 8, W, 8) end BASE_STAGE = 2 end end local WAVES = { { 230, 14.0, 0 }, { 340, 10.0, 130 } } local CORE = { 0.05, 0.05, 0.05, 0.07, 0.09, 0.10, 0.11, 0.12 } function render() if BASE_STAGE < 2 then build() end if BASE_STAGE < 2 then gfx.ready(false) return end for g = 0, 7 do gfx.blit_rgb(STRIP[g], 0, g * 8, W, 8) end for _, wv in ipairs(WAVES) do local t = ((frame + wv[3]) % wv[1]) / 30 for g = 0, 7 do local c = floor(-14 + wv[2] * t - g * 3) if c > -10 and c < W + 10 then local a = CORE[g + 1] blend_rect(c - 9, g * 8, 5, 8, 255, 244, 200, a * 0.5) blend_rect(c - 4, g * 8, 8, 8, 255, 244, 200, a) blend_rect(c + 4, g * 8, 5, 8, 255, 244, 200, a * 0.5) end end end end