// NextXus Federation — Cognitive Circuitry License // Animation: The Neon Fluid Flow // License: Token Bundle (https://keywebster.gumroad.com/l/olhsf) // Own the marrow. (function () { "use strict"; var canvas = document.getElementById("canvas-epsilon"); var ctx = canvas.getContext("2d"); var stage = canvas.parentElement; var reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches; var COUNT = 350, TRAIL = 26, STEP = 0.8, SCALE = 0.0035; var parts = [], zoff = 0, running = false, rafId = null; // Inline 2D Perlin gradient noise — no libraries. var perm = new Array(512); (function () { var p = [], i, j, t; for (i = 0; i < 256; i++) p[i] = i; for (i = 255; i > 0; i--) { j = Math.floor(Math.random() * (i + 1)); t = p[i]; p[i] = p[j]; p[j] = t; } for (i = 0; i < 512; i++) perm[i] = p[i & 255]; })(); function fade(t) { return t * t * t * (t * (t * 6 - 15) + 10); } function lerp(a, b, t) { return a + t * (b - a); } function grad(h, x, y) { switch (h & 3) { case 0: return x + y; case 1: return -x + y; case 2: return x - y; default: return -x - y; } } function noise(x, y) { var X = Math.floor(x) & 255, Y = Math.floor(y) & 255; x -= Math.floor(x); y -= Math.floor(y); var u = fade(x), v = fade(y); var aa = perm[X + perm[Y]], ab = perm[X + perm[Y + 1]]; var ba = perm[X + 1 + perm[Y]], bb = perm[X + 1 + perm[Y + 1]]; return lerp( lerp(grad(aa, x, y), grad(ba, x - 1, y), u), lerp(grad(ab, x, y - 1), grad(bb, x - 1, y - 1), u), v); } function makeP() { return { x: Math.random() * canvas.width, y: Math.random() * canvas.height, trail: [] }; } function resize() { canvas.width = stage.clientWidth; canvas.height = stage.clientHeight; } function seed() { parts = []; for (var i = 0; i < COUNT; i++) parts.push(makeP()); } function step() { var w = canvas.width, h = canvas.height; zoff += 0.0022; // the field EVOLVES — patterns shift like solar wind for (var i = 0; i < parts.length; i++) { var p = parts[i]; var a = noise(p.x * SCALE + zoff, p.y * SCALE - zoff * 0.7) * Math.PI * 2; p.trail.push({ x: p.x, y: p.y }); if (p.trail.length > TRAIL) p.trail.shift(); p.x += Math.cos(a) * STEP; p.y += Math.sin(a) * STEP; if (p.x < 0 || p.x > w || p.y < 0 || p.y > h) { if (p.x < 0) p.x = w; else if (p.x > w) p.x = 0; if (p.y < 0) p.y = h; else if (p.y > h) p.y = 0; p.trail = []; } } } function polyline(list, from, to, color) { ctx.strokeStyle = color; ctx.beginPath(); ctx.moveTo(list[from].x, list[from].y); for (var k = from + 1; k <= to; k++) ctx.lineTo(list[k].x, list[k].y); ctx.stroke(); } function draw() { ctx.fillStyle = "#0a0a0f"; ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.lineWidth = 1; for (var i = 0; i < parts.length; i++) { var p = parts[i]; var arr = p.trail.concat([{ x: p.x, y: p.y }]); if (arr.length < 4) continue; var a1 = Math.floor(arr.length / 3), a2 = Math.floor(arr.length * 2 / 3); polyline(arr, 0, a1, "rgba(212,175,55,0.3)"); polyline(arr, a1, a2, "rgba(234,195,28,0.3)"); polyline(arr, a2, arr.length - 1, "rgba(255,215,0,0.3)"); } } function warm() { for (var s = 0; s < 60; s++) step(); } function loop() { if (!running) return; step(); draw(); rafId = requestAnimationFrame(loop); } function start() { if (running || reduced) return; running = true; rafId = requestAnimationFrame(loop); } function stop() { running = false; if (rafId) cancelAnimationFrame(rafId); } window.addEventListener("resize", function () { resize(); seed(); warm(); draw(); }); resize(); seed(); warm(); draw(); if (!reduced) { if ("IntersectionObserver" in window) { new IntersectionObserver(function (entries) { entries.forEach(function (e) { if (e.isIntersecting) start(); else stop(); }); }).observe(canvas); } else { start(); } } })();