info = { type = "image", title = "Wave bands", category = "patterns", author = "BRRRO", version = "1.0", license = "MIT", desc = "Slow rainbow bands flowing in waves", api = 33, } local tr = ({ sk = { ["Palette"] = "Paleta", ["Rainbow"] = "Dúha", ["Sunset"] = "Západ", ["Ocean"] = "Oceán", ["Pastel"] = "Pastel", ["Speed"] = "Rýchlosť", ["Lines"] = "Čiary", ["Light"] = "Svetlé", ["None"] = "Žiadne" }, cs = { ["Palette"] = "Paleta", ["Rainbow"] = "Duha", ["Sunset"] = "Západ", ["Ocean"] = "Oceán", ["Pastel"] = "Pastel", ["Speed"] = "Rychlost", ["Lines"] = "Čáry", ["Light"] = "Světlé", ["None"] = "Žádné" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "pal", label = T("Palette"), type = "int", default = "rainbow", opts = { keys = { "rainbow", "sunset", "ocean", "pastel" }, T("Rainbow"), T("Sunset"), T("Ocean"), T("Pastel") } }, { key = "speed", label = T("Speed"), type = "int", min = 1, max = 5, default = 3 }, { key = "lines", label = T("Lines"), type = "int", default = "light", opts = { keys = { "light", "none" }, T("Light"), T("None") } }, } local rect, blend_rect = gfx.rect, gfx.blend_rect local floor, sin, cos, max, min = math.floor, math.sin, math.cos, math.max, math.min local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local NB = 7 local TAU = 6.2831853 local ST, S1, C1, S2, C2, W1, W2 = {}, {}, {}, {}, {}, {}, {} for k = 1, NB - 1 do local h = hash32(k * 0x9E3779B1) local f1 = TAU / W * (1.0 + umod(h, 50) / 100) local f2 = TAU / W * (2.0 + umod(h >> 6, 80) / 100) local p1, p2 = umod(h >> 12, 628) / 100, umod(h >> 18, 628) / 100 local tilt, arch = 5 * cos(k * 1.7), 3 * sin(k * 2.3) W1[k] = 0.45 + umod(h >> 8, 40) / 100 W2[k] = 0.7 + umod(h >> 14, 50) / 100 ST[k], S1[k], C1[k], S2[k], C2[k] = {}, {}, {}, {}, {} for x = 0, W - 1 do local u = (x - 31.5) / 32 ST[k][x] = H * k / NB + tilt * u + arch * (1 - u * u) S1[k][x], C1[k][x] = 3.2 * sin(f1 * x + p1), 3.2 * cos(f1 * x + p1) S2[k][x], C2[k][x] = 1.5 * sin(f2 * x + p2), 1.5 * cos(f2 * x + p2) end end local function hsv(h, s, v) h = (h % 360) / 60 local i = floor(h) local f = h - i local p, q, t = v * (1 - s), v * (1 - s * f), v * (1 - s * (1 - f)) i = i % 6 local r, g, b if i == 0 then r, g, b = v, t, p elseif i == 1 then r, g, b = q, v, p elseif i == 2 then r, g, b = p, v, t elseif i == 3 then r, g, b = p, q, v elseif i == 4 then r, g, b = t, p, v else r, g, b = v, p, q end return floor(r * 255 + 0.5), floor(g * 255 + 0.5), floor(b * 255 + 0.5) end local function band_colour(pal, k, ph) local u = (ph + k / NB) % 1 if pal == "rainbow" then return hsv(360 * u, 0.95, 1) end if pal == "pastel" then return hsv(360 * u, 0.5, 1) end local tri = 1 - math.abs(2 * u - 1) local v = k % 2 == 0 and 1 or 0.8 if pal == "sunset" then return hsv(335 + 85 * tri, 0.92, v) end return hsv(165 + 100 * tri, 0.88, v) end local SPEEDS = { 0.4, 0.7, 1.0, 1.5, 2.2 } local CR, CG, CB = {}, {}, {} local CW1, SW1, CW2, SW2 = {}, {}, {}, {} function render() local t = frame / FPS * SPEEDS[cfg.speed or 3] local pal = cfg.pal or "rainbow" local line = cfg.lines ~= "none" for k = 0, NB - 1 do CR[k], CG[k], CB[k] = band_colour(pal, k, t / 40) end for k = 1, NB - 1 do CW1[k], SW1[k], CW2[k], SW2[k] = cos(W1[k] * t), sin(W1[k] * t), cos(W2[k] * t), sin(W2[k] * t) end for x = 0, W - 2, 2 do rect(x, 0, 2, H, CR[0], CG[0], CB[0]) local prev = -2 for k = 1, NB - 1 do local y = ST[k][x] + S1[k][x] * CW1[k] + C1[k][x] * SW1[k] + S2[k][x] * CW2[k] - C2[k][x] * SW2[k] if y < prev + 2 then y = prev + 2 end prev = y if y > H - 2 then y = H - 2 end local i = y // 1 local f = y - i rect(x, i + 1, 2, H - i - 1, CR[k], CG[k], CB[k]) if line then blend_rect(x, i, 2, 1, 255, 255, 255, 0.9 * (1 - f)) blend_rect(x, i + 1, 2, 1, 255, 255, 255, 0.9 * f) else blend_rect(x, i, 2, 1, CR[k], CG[k], CB[k], 1 - f) end end end end