info = { type = "image", title = "Glow shrooms", category = "nature", author = "BRRRO", version = "1.0", license = "MIT", desc = "Glowing mushrooms puff spores at night", api = 33, } local ltr = ({ sk = { ["Glow colour"] = "Farba žiary", ["Spores"] = "Spóry" }, cs = { ["Glow colour"] = "Barva záře", ["Spores"] = "Spóry" }, })[lang] or {} local function LT(s) return ltr[s] or s end settings = { { key = "glow", label = LT("Glow colour"), type = "color", default = "#46F0C8" }, { key = "spores", label = LT("Spores"), type = "int", min = 0, max = 24, default = 14 }, } local rect, px, blend = gfx.rect, gfx.px, gfx.blend 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, SKY_LO = { 20, 34, 84 }, { 32, 54, 110 } local TRUNK = { 12, 24, 54 } local GROUND, MOSS = { 18, 40, 46 }, { 52, 104, 84 } local MOON = { 236, 232, 190 } local STAR, STAR_DIM = { 220, 230, 255 }, { 96, 112, 170 } local STEM, STEM_L = { 150, 168, 160 }, { 200, 214, 204 } local HAZE = 35 local function c3(c) return c[1], c[2], c[3] end local function mix(c, d, k) return floor(c[1] + (d[1] - c[1]) * k), floor(c[2] + (d[2] - c[2]) * k), floor(c[3] + (d[3] - c[3]) * k) end local function ground_y(x) return 53 + floor(1.2 * sin(x * 0.13 + 0.5) + 0.5) end local M = { { cx = 22, top = 25, rx = 11, ry = 7, sw = 5, R = 5, per = 3.6, ph = 0.0 }, { cx = 46, top = 37, rx = 7, ry = 5, sw = 3, R = 4, per = 2.9, ph = 2.1 }, { cx = 56, top = 46, rx = 4, ry = 3, sw = 2, R = 3, per = 2.3, ph = 4.0 }, { cx = 9, top = 45, rx = 4, ry = 3, sw = 2, R = 3, per = 2.6, ph = 1.2 }, { cx = 33, top = 49, rx = 3, ry = 2, sw = 1, R = 3, per = 2.0, ph = 3.1 }, } for i = 1, #M do local m = M[i] m.hw = {} for r = 0, m.ry - 1 do local k = (m.ry - r - 0.5) / m.ry local hw = floor(m.rx * sqrt(1 - k * k) + 0.5) m.hw[r] = hw < 1 and 1 or hw end m.hw[m.ry] = m.rx - 1 m.gy = ground_y(m.cx) end local RUNS = { { 0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 21, 28 }, { 40, 1, 2, 3, 4, 5, 7, 9, 13, 15, 21, 27 }, { 80, 1, 2, 5, 7, 9, 11, 13, 14, 15, 17, 21, 23 }, { 90, 1, 2, 5, 6, 9, 11, 12, 14, 15, 19, 23 }, { 95, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 13, 17 }, { 120, 1, 5, 7, 13, 21 }, { 160, 1, 2, 3, 4, 6, 7, 9, 11 } } local UNZ = { ["\n"] = "" } do local c = 33 for _, r in ipairs(RUNS) do local v = string.char(r[1]) for k = 2, #r do if c == 93 then c = 94 end UNZ[string.char(c)] = v:rep(r[k]) c = c + 1 end end end local function unz(s) return (s:gsub(".", UNZ)) end local MASKZ = { [[ +91;.7_7*5a5'6XnX6%5WjBjW5$4WhFhW4#4ViGiV4"4VgHgV4"3VhHhV3!4VgIgV6VgIgV4!3VhfhV3"4Vm7mV4"5^7^5#5\7\5 %=(<072727272727272727272727272727O.K7N'T+S(]], [[ '8-3\3)3`3&3WmW3%3ViAiV3#3VhChV3"VhDhV!3VgFgV4VgFgV3!VhehV"3Vk5kV3#3[5[3%3Z5Z3':.505050505+L#5-M5/R( P$]], [[ $[&\%VlV#Vh@hV!VhAhXgBgXhdhV!Vi4jV#X4Y%W4X(4'L4M$N'L%]], [[ $[&\%VlV#Vh@hV!VhAhXgBgXhdhV!Vi4jV#X4Y%W4X(4,4'L4M$N'L%]], [[ #[%\#VlV!Vh@hXgAgXhchV!Vi3iV#\%[#]] } for i = 1, #M do local m = M[i] local x0, y0 = m.cx - m.rx - m.R, m.top - m.R m.mask, m.mx, m.my, m.mw, m.mh = unz(MASKZ[i]), x0, y0, 2 * (m.rx + m.R) + 1, m.gy + 2 - y0 + 1 end local BG = nil local GR, GG, GB = 70, 240, 200 local function build_bg() rect(0, 0, W, H, c3(SKY)) rect(0, HAZE, W, H - HAZE, c3(SKY_LO)) for x = 0, W - 1, 2 do px(x, HAZE - 1, c3(SKY_LO)) end for y = 3, 13 do for x = 47, 59 do local a, b = (x - 53) ^ 2 + (y - 8) ^ 2, (x - 55) ^ 2 + (y - 7) ^ 2 if a <= 20 and b > 17 then px(x, y, c3(MOON)) end end end for i = 1, 14 do local h = hash32(i * 0x9E3779B1) px(umod(h, W), umod(h >> 8, HAZE - 4), c3((h >> 16) & 1 == 1 and STAR or STAR_DIM)) end local T = { { 2, 4 }, { 38, 3 }, { 59, 5 } } for i = 1, #T do rect(T[i][1], 0, T[i][2], H, c3(TRUNK)) end rect(6, 14, 4, 1, c3(TRUNK)); rect(9, 13, 2, 1, c3(TRUNK)) rect(34, 20, 4, 1, c3(TRUNK)); rect(32, 19, 2, 1, c3(TRUNK)) rect(55, 26, 4, 1, c3(TRUNK)); rect(53, 25, 2, 1, c3(TRUNK)) for x = 0, W - 1 do local gy = ground_y(x) rect(x, gy, 1, H - gy, c3(GROUND)) px(x, gy, c3(MOSS)) if umod(hash32(x * 0x85EBCA6B), 5) == 0 then px(x, gy - 1, c3(MOSS)) end end local G = { GR, GG, GB } local cr, cg, cb = mix(G, { 0, 0, 0 }, 0.45) local lr, lg, lb = mix(G, { 0, 0, 0 }, 0.2) local sr, sg, sb = mix(G, { 255, 255, 255 }, 0.6) local gr, gg, gb = mix(G, { 255, 255, 255 }, 0.3) for i = 1, #M do local m = M[i] local sx, s0 = m.cx - m.sw // 2, m.top + m.ry + 1 rect(sx, s0, m.sw, m.gy - s0 + 1, c3(STEM)) rect(sx, s0, 1, m.gy - s0 + 1, c3(STEM_L)) if m.sw >= 3 then rect(sx - 1, s0 + 3, m.sw + 2, 1, c3(STEM_L)) end for r = 0, m.ry - 1 do local hw = m.hw[r] rect(m.cx - hw, m.top + r, 2 * hw + 1, 1, cr, cg, cb) if r >= 1 and r <= 2 then rect(m.cx - hw + 1, m.top + r, hw - 1, 1, lr, lg, lb) end end rect(m.cx - m.hw[m.ry], m.top + m.ry, 2 * m.hw[m.ry] + 1, 1, gr, gg, gb) for k = 1, m.rx // 2 do local h = hash32(i * 0x27D4EB2F + k * 0x165667B1) local r = 1 + umod(h, m.ry - 1) local hw = m.hw[r] - 1 px(m.cx - hw + umod(h >> 8, 2 * hw + 1), m.top + r, sr, sg, sb) end end BG = gfx.snapshot(0, 0, W, H) end local PICK = { 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5 } local SV, SL, SP, SO = {}, {}, {}, {} for i = 1, 24 do local h = hash32(i * 0xC2B2AE35) SV[i] = 3 + umod(h, 10) * 0.3 SL[i] = 3.3 + umod(h >> 8, 200) / 100 SP[i] = SL[i] + umod(h >> 16, 170) / 100 SO[i] = umod(h >> 4, floor(SP[i] * 100)) / 100 end local SR, SG, SB = 160, 248, 228 local function draw_spores(t, n) for i = 1, n do local q = t + SO[i] local pass, u = floor(q / SP[i]), q % SP[i] local L = SL[i] if u < L then local h = hash32(pass * 0x9E3779B1 + i * 0x85EBCA6B) local m = M[PICK[umod(h, #PICK) + 1]] local hw = m.hw[1] local x = m.cx - hw + umod(h >> 8, 2 * hw + 1) + 1.4 * sin(u * 2.1 + (h >> 16 & 63) * 0.1) local y = m.top - u * SV[i] local a = 0.9 if u < 0.4 then a = a * u / 0.4 end if u > L * 0.6 then a = a * (L - u) / (L * 0.4) end local xi, yi = floor(x), floor(y) local fx, fy = x - xi, y - yi blend(xi, yi, SR, SG, SB, a * (1 - fx) * (1 - fy)) blend(xi + 1, yi, SR, SG, SB, a * fx * (1 - fy)) blend(xi, yi + 1, SR, SG, SB, a * (1 - fx) * fy) blend(xi + 1, yi + 1, SR, SG, SB, a * fx * fy) end end end function on_settings() local c = cfg.glow or { r = 70, g = 240, b = 200 } GR, GG, GB = c.r, c.g, c.b SR, SG, SB = (c.r + 255) // 2, (c.g + 255) // 2, (c.b + 255) // 2 BG = nil end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local t = frame / FPS for i = 1, #M do local m = M[i] local k = 0.6 + 0.35 * sin(t * TAU / m.per + m.ph) gfx.blend_mask(m.mask, GR, GG, GB, m.mx, m.my, m.mw, m.mh, m.mw, m.mh, k) end draw_spores(t, cfg.spores or 14) end