Skip to content

Commit a809e84

Browse files
committed
feat: Implement Cluster Drift (Flow Fields) for Neural Swarm (#8672)
1 parent 691a7e5 commit a809e84

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

apps/portal/canvas/HomeCanvas.mjs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -850,9 +850,21 @@ class HomeCanvas extends Base {
850850
buffer[idx + 2] *= 0.95; // Friction
851851
buffer[idx + 3] *= 0.95;
852852

853-
let drift = isParent ? 0.02 : 0.01;
854-
if (Math.abs(buffer[idx + 2]) < 0.2) buffer[idx + 2] += (Math.random() - 0.5) * drift;
855-
if (Math.abs(buffer[idx + 3]) < 0.2) buffer[idx + 3] += (Math.random() - 0.5) * drift;
853+
// 4. Ambient Drift / Flow Field
854+
if (isParent) {
855+
// FLOW FIELD for Parents: Create organic currents
856+
// Combine Sine/Cosine based on position and time
857+
let angle = (Math.cos(buffer[idx] * 0.002 + me.time * 0.5) +
858+
Math.sin(buffer[idx + 1] * 0.002 + me.time * 0.5)) * Math.PI;
859+
860+
// Accelerate in flow direction
861+
buffer[idx + 2] += Math.cos(angle) * 0.05;
862+
buffer[idx + 3] += Math.sin(angle) * 0.05;
863+
} else {
864+
// Random wander for children
865+
if (Math.abs(buffer[idx + 2]) < 0.2) buffer[idx + 2] += (Math.random() - 0.5) * 0.02;
866+
if (Math.abs(buffer[idx + 3]) < 0.2) buffer[idx + 3] += (Math.random() - 0.5) * 0.02;
867+
}
856868

857869
buffer[idx] += buffer[idx + 2];
858870
buffer[idx + 1] += buffer[idx + 3];

0 commit comments

Comments
 (0)