File size: 1,694 Bytes
e135b5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const logEl = document.getElementById("log");
const psiInput = document.getElementById("psiInput");
const svg = document.getElementById("svgEngine");

const log = msg => {
  logEl.innerHTML += msg + "<br>";
  logEl.scrollTop = logEl.scrollHeight;
};

// Initialize SVG Core + Nodes
function makeSVGElem(tag, attrs) {
  const el = document.createElementNS("http://www.w3.org/2000/svg", tag);
  for (let k in attrs) el.setAttribute(k, attrs[k]);
  return el;
}

const core = makeSVGElem("circle", { cx: 0, cy: 0, r: 35, fill: "#00ffff" });
svg.appendChild(core);

const nodesGroup = document.createElementNS("http://www.w3.org/2000/svg", "g");
svg.appendChild(nodesGroup);

let nodes = [];
const NODE_COUNT = 14;
for (let i = 0; i < NODE_COUNT; i++) {
  const node = makeSVGElem("circle", { r: 5, fill: "#00ffcc" });
  nodesGroup.appendChild(node);
  nodes.push(node);
}

let state = {
  theta: 0,
  iter: 0,
  psiStrength: 1
};

function stepEngine() {
  state.iter++;
  state.theta += 0.015 * state.psiStrength;
  const radius = 40 + 12 * Math.sin(state.theta);

  core.setAttribute("r", 30 + 6 * Math.sin(state.iter * 0.05));

  nodes.forEach((n, idx) => {
    const angle = state.theta + (idx * 2 * Math.PI / nodes.length);
    n.setAttribute("cx", Math.cos(angle) * radius);
    n.setAttribute("cy", Math.sin(angle) * radius);
  });
}

psiInput.addEventListener("keydown", e => {
  if (e.key === "Enter") {
    const psi = e.target.value.trim();
    if (psi.length) {
      state.psiStrength = Math.min(3, Math.max(0.5, psi.length * 0.1));
      log(`Ψ(t) injected: "${psi}"`);
      e.target.value = "";
    }
  }
});

setInterval(stepEngine, 40);
log("System online. Awaiting Ψ(t) …");