info = { type = "image", title = "Plasma", category = "patterns", author = "BRRRO", version = "1.0", license = "MIT", desc = "A field of colour waves", api = 33, } local CW, CH = 32, 32 local NC = 48 local TAU, K = 6.2831853, 40.7436654 local SIN = {} for i = 0, 255 do SIN[i] = math.floor(math.sin(i * TAU / 256) * 512 + 0.5) end local RAD, sx, sxy, cells, pal = nil, {}, {}, {}, {} local STEP_HZ = 30 function render() local W, H = gfx.W, gfx.H local t = frame * STEP_HZ // gfx.FPS local sin = SIN if not RAD then RAD = {} local sqrt = math.sqrt for cy = 0, CH - 1 do local dy = cy * 2 - (H // 2 - 2) for cx = 0, CW - 1 do local dx = cx * 2 - W // 2 RAD[cy * CW + cx + 1] = sqrt(dx * dx + dy * dy) * 0.18 * K // 1 | 0 end end end local paI = ((t * 0.08 % TAU) * K + 2048) // 1 | 0 local pbI = ((t * -0.06 % TAU) * K + 2048) // 1 | 0 local pcI = ((t * 0.1 % TAU) * K + 2048) // 1 | 0 local pdI = ((t * -0.12 % TAU) * K + 2048) // 1 | 0 local phK = (t * 0.06 % TAU) * K + 2048 for k = 1, NC do local hi = ((k - 0.5) * 8 / NC - 4) * 1.2 * K + phK pal[3 * k - 2] = 150 + 95 * sin[hi // 1 & 255] / 512 // 1 pal[3 * k - 1] = 150 + 95 * sin[(hi + 2.1 * K) // 1 & 255] / 512 // 1 pal[3 * k] = 158 + 90 * sin[(hi + 4.2 * K) // 1 & 255] / 512 // 1 end if t % 2 == 0 or not cells[1] then for cx = 0, CW - 1 do sx[cx] = sin[(cx * 2 * 0.16 * K + paI) // 1 & 255] end for s = 0, CW + CH - 2 do sxy[s] = sin[(s * 2 * 0.12 * K + pcI) // 1 & 255] end for cy = 0, CH - 1 do local sy = sin[(cy * 2 * 0.18 * K + pbI) // 1 & 255] local base = cy * CW for cx = 0, CW - 1 do local i = base + cx + 1 local v = sx[cx] + sy + sxy[cx + cy] + sin[(RAD[i] + pdI) & 255] local k = (v + 2048) * 3 >> 8 if k < 0 then k = 0 elseif k >= NC then k = NC - 1 end cells[i] = k end end end gfx.blit_indexed(cells, pal, 0, 0, W, H, CW, CH) end