info = { type = "image", title = "Matrix rain", category = "patterns", author = "BRRRO", version = "1.0", license = "MIT", desc = "Thin streaks falling with bright heads", api = 33, } local tr = ({ sk = { ["Colour"] = "Farba", ["Head"] = "Hlava", ["Speed"] = "Rýchlosť", ["Density"] = "Hustota" }, cs = { ["Colour"] = "Barva", ["Head"] = "Hlava", ["Speed"] = "Rychlost", ["Density"] = "Hustota" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "tail", label = T("Colour"), type = "color", default = "#00D2A0" }, { key = "head", label = T("Head"), type = "color", default = "#E6FFF6" }, { key = "speed", label = T("Speed"), type = "int", min = 1, max = 8, default = 3 }, { key = "dense", label = T("Density"), type = "int", min = 1, max = 10, default = 6 }, } local LMIN, LMAX = 5, 22 local BASE = 31 local function h(a, b, c) return math.hash32(a * 7919 + b * 104729 + c * 15485863) & 0x7FFF end local X, V, SPAN, OFF, NL = {}, {}, {}, {}, 0 local function lanes() for x = 0, gfx.W - 1 do for lane = 0, 1 do NL = NL + 1 X[NL] = x V[NL] = BASE * (0.5 + h(x, lane, 1) / 0x7FFF * 0.9) SPAN[NL] = gfx.H + LMAX + 8 + h(x, lane, 2) % 40 OFF[NL] = h(x, lane, 3) % SPAN[NL] end end end function render() if NL == 0 then lanes() end local tc, hc = cfg.tail or { r = 0, g = 210, b = 160 }, cfg.head or { r = 230, g = 255, b = 246 } local t = frame * ((cfg.speed or 3) + 2) / 5 / gfx.FPS local dense = (cfg.dense or 6) * 10 local r1, g1, b1 = tc.r * 3 // 10, tc.g * 3 // 10, tc.b * 3 // 10 local r2, g2, b2 = tc.r * 6 // 10, tc.g * 6 // 10, tc.b * 6 // 10 local rm, gm, bm = (tc.r + hc.r) // 2, (tc.g + hc.g) // 2, (tc.b + hc.b) // 2 local rect, px, hash, floor = gfx.rect, gfx.px, math.hash32, math.floor gfx.clear(0, 0, 0) for i = 1, NL do local span = SPAN[i] local pos = t * V[i] + OFF[i] local n = floor(pos / span) local key = X[i] * 7919 + i * 104729 + n * 15485863 if (hash(key) & 0x7FFF) % 100 < dense then local x = X[i] local yf = pos % span - 8 local y = floor(yf) local f = yf - y local L = LMIN + (hash(key + 1) & 0x7FFF) % (LMAX - LMIN + 1) local a = L // 3 rect(x, y - L, 1, a, r1, g1, b1) rect(x, y - L + a, 1, a, r2, g2, b2) rect(x, y - L + 2 * a, 1, L - 2 * a - 1, tc.r, tc.g, tc.b) px(x, y - 1, rm, gm, bm) px(x, y, hc.r, hc.g, hc.b) px(x, y + 1, hc.r * f // 1, hc.g * f // 1, hc.b * f // 1) end end end