info = { type = "image", title = "Prism fold", category = "patterns", author = "BRRRO", version = "1.0", license = "MIT", desc = "Mirrored colour facets flow in a kaleidoscope", api = 33, } local tr = ({ sk = { ["Segments"] = "Segmenty", ["Palette"] = "Paleta", ["Speed"] = "Rýchlosť", ["Ocean"] = "Oceán", ["Amber"] = "Jantár", ["Orchid"] = "Orchidea" }, cs = { ["Segments"] = "Segmenty", ["Palette"] = "Paleta", ["Speed"] = "Rychlost", ["Ocean"] = "Oceán", ["Amber"] = "Jantar", ["Orchid"] = "Orchidej" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "segs", label = T("Segments"), type = "int", default = 1, opts = { "6", "8", "12" } }, { key = "pal", label = T("Palette"), type = "int", default = 0, opts = { T("Ocean"), T("Amber"), T("Orchid") } }, { key = "speed", label = T("Speed"), type = "int", min = 1, max = 5, default = 3 }, } local floor, sin, cos, sqrt, atan = math.floor, math.sin, math.cos, math.sqrt, math.atan local blit = gfx.blit_indexed local PI = math.pi local M1, M2 = 48, 32 local PALS = { { { { 8, 24, 64 }, { 16, 112, 170 }, { 40, 200, 200 }, { 200, 250, 240 }, { 12, 60, 120 } }, { { 120, 230, 255 }, { 250, 250, 255 }, { 30, 150, 200 } } }, { { { 60, 18, 10 }, { 176, 70, 20 }, { 248, 160, 40 }, { 255, 232, 150 }, { 120, 40, 16 } }, { { 255, 240, 190 }, { 255, 196, 90 }, { 190, 90, 30 } } }, { { { 48, 14, 84 }, { 150, 40, 170 }, { 236, 100, 200 }, { 252, 206, 240 }, { 84, 30, 140 } }, { { 255, 220, 250 }, { 224, 140, 240 }, { 160, 70, 210 } } }, } local K1, K2 = PALS[1][1], PALS[1][2] local P1, P2 = {}, { 0, 0, 0 } local G1, G2, BUILD local function fill(P, K, M, s, off) local nk = #K for i = 0, M - 1 do local q = ((i + s) % M) / M * nk local k = floor(q) local f = q - k f = f < 0.55 and 0 or (f - 0.55) / 0.45 f = f * f * (3 - 2 * f) local a, b = K[k + 1], K[(k + 1) % nk + 1] local o = (i + off) * 3 P[o + 1] = floor(a[1] + (b[1] - a[1]) * f + 0.5) P[o + 2] = floor(a[2] + (b[2] - a[2]) * f + 0.5) P[o + 3] = floor(a[3] + (b[3] - a[3]) * f + 0.5) end end local SEGS = { 6, 8, 12 } local ROWS_PER_FRAME = 6 function on_settings() K1, K2 = PALS[cfg.pal + 1][1], PALS[cfg.pal + 1][2] local n = SEGS[cfg.segs + 1] or 8 if not BUILD or BUILD.n ~= n then BUILD = { n = n, i = 0, ra = {}, rb = {} } end end local function step(B) local al = PI / B.n local al2 = 2 * al local a, b = {}, {} for y = B.i, math.min(B.i + ROWS_PER_FRAME, 64) - 1 do for x = 0, 63 do local dx, dy = x + 0.5 - 32, y + 0.5 - 32 local r = sqrt(dx * dx + dy * dy) local m = atan(dy, dx) % al2 local tf = m > al and al2 - m or m local u, v = r * cos(tf), r * sin(tf) local f1 = sin(0.30 * u + 1.1 * sin(0.19 * v)) + sin(0.26 * v - 0.17 * u + 1.0) + 0.9 * sin(0.55 * r + 0.6 * sin(0.3 * u)) a[x + 1] = floor(f1 * 2.6 + r * 0.7 + 60) % M1 local f2 = sin(0.52 * u + 0.8) * sin(0.47 * v + 0.3) + 0.5 * sin(0.35 * r) b[x + 1] = f2 > 0.35 and floor(f2 * 14 + 40) % M2 + 1 or 0 end B.ra[y + 1] = string.char(table.unpack(a)) B.rb[y + 1] = string.char(table.unpack(b)) end B.i = B.i + ROWS_PER_FRAME if B.i >= 64 then G1, G2, B.done = table.concat(B.ra), table.concat(B.rb), true end end function render() if BUILD and not BUILD.done then step(BUILD) end if not G1 then gfx.clear(0, 0, 0); return end local sp = (cfg.speed or 3) / 3 fill(P1, K1, M1, frame * 0.10 * sp, 0) fill(P2, K2, M2, -frame * 0.07 * sp, 1) blit(G1, P1, 0, 0, 64, 64, 64, 64) blit(G2, P2, 0, 0, 64, 64, 64, 64, true) end