// NextXus Federation — Cognitive Circuitry License // Animation: The Atmospheric Nebula // License: Token Bundle (https://keywebster.gumroad.com/l/olhsf) // Own the marrow. (function () { "use strict"; var canvas = document.getElementById("canvas-kappa"); var ctx = canvas.getContext("2d"); var stage = canvas.parentElement; var reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches; var PARTICLE_COUNT_MULT = 5, SIZE_MULT = 3, SPEED = 25, CONNECTION_DENSITY = 12, LINE_WIDTH = 0.8; var CYAN = "#00D4FF", GOLD = "#f4b942"; var particles = [], connectionsOn = false, running = false, rafId = null; function resize() { canvas.width = stage.clientWidth; canvas.height = stage.clientHeight; } function connectDist() { return CONNECTION_DENSITY * 10; } function seed() { var count = Math.floor((canvas.width * canvas.height) / 25000 * PARTICLE_COUNT_MULT); particles = []; for (var i = 0; i < count; i++) { particles.push({ x: Math.random() * canvas.width, y: Math.random() * canvas.height, vx: (Math.random() - 0.5) * (SPEED / 30), vy: (Math.random() - 0.5) * (SPEED / 30), r: (0.5 + Math.random()) * SIZE_MULT, color: Math.random() < 0.5 ? CYAN : GOLD }); } } function connect() { if (!connectionsOn) return; var dist = connectDist(); for (var i = 0; i < particles.length; i++) { for (var j = i + 1; j < particles.length; j++) { var dx = particles[i].x - particles[j].x; var dy = particles[i].y - particles[j].y; var d = Math.sqrt(dx * dx + dy * dy); if (d < dist) { ctx.strokeStyle = particles[i].color; ctx.globalAlpha = (1 - d / dist) * 0.5; ctx.lineWidth = LINE_WIDTH; ctx.beginPath(); ctx.moveTo(particles[i].x, particles[i].y); ctx.lineTo(particles[j].x, particles[j].y); ctx.stroke(); } } } ctx.globalAlpha = 1; } function draw() { ctx.clearRect(0, 0, canvas.width, canvas.height); connect(); for (var i = 0; i < particles.length; i++) { var p = particles[i]; ctx.fillStyle = p.color; ctx.beginPath(); ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2); ctx.fill(); } } function step() { for (var i = 0; i < particles.length; i++) { var p = particles[i]; p.x += p.vx; p.y += p.vy; if (p.x < 0 || p.x > canvas.width) { p.vx *= -1; p.x = Math.max(0, Math.min(canvas.width, p.x)); } if (p.y < 0 || p.y > canvas.height) { p.vy *= -1; p.y = Math.max(0, Math.min(canvas.height, p.y)); } } } 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); } var btnDrift = document.getElementById("kappa-btn-drift"); var btnWeb = document.getElementById("kappa-btn-web"); function setMode(web) { connectionsOn = web; btnDrift.classList.toggle("kappa-btn--active", !web); btnWeb.classList.toggle("kappa-btn--active", web); btnDrift.setAttribute("aria-pressed", String(!web)); btnWeb.setAttribute("aria-pressed", String(web)); if (reduced) draw(); } btnDrift.addEventListener("click", function () { setMode(false); }); btnWeb.addEventListener("click", function () { setMode(true); }); window.addEventListener("resize", function () { resize(); seed(); draw(); }); resize(); seed(); 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(); } } })();