xxxxxxxxxx
129
let nodes = [];
let connections = [];
let state = 0; // Represents different effects
let t = 0; // Noise time offset
function setup() {
createCanvas(windowWidth, windowHeight);
for (let i = 0; i < 100; i++) {
let x = random(width);
let y = random(height);
nodes.push(new Node(x, y));
}
for (let i = 0; i < nodes.length; i++) {
for (let j = i + 1; j < nodes.length; j++) {
if (dist(nodes[i].x, nodes[i].y, nodes[j].x, nodes[j].y) < 150) {
connections.push(new Connection(nodes[i], nodes[j]));
}
}
}
}
function draw() {
background(20);
// Render connections and nodes
for (let connection of connections) {
connection.show(state);
}
for (let node of nodes) {
node.update(state);
node.show(state);
}
t += 0.01;
}
// Node class represents points in the network
class Node {
constructor(x, y) {
this.x = x;
this.y = y;
this.offsetX = random(1000);
this.offsetY = random(1000);
this.baseSize = random(5, 10); // Base size of the node
}
update(state) {
let noiseFactor = 1;
if (state === 0) noiseFactor = 0.3; // Calm: minimal movement
if (state === 1) noiseFactor = 3; // Anxious: erratic movement
if (state === 2) noiseFactor = 1.5; // Euphoric: pulsating movement
if (state === 3) noiseFactor = 0.1; // Focused: almost no noise
if (state === 4) noiseFactor = 5; // Disoriented: chaotic movement
// Apply noise-based motion
this.x += map(noise(this.offsetX + t), 0, 1, -1, 1) * noiseFactor;
this.y += map(noise(this.offsetY + t), 0, 1, -1, 1) * noiseFactor;
// Keep nodes within bounds
this.x = constrain(this.x, 0, width);
this.y = constrain(this.y, 0, height);
// Modify size based on state
if (state === 2) {
this.size = this.baseSize + sin(t * 10) * 3; // Euphoric: Pulsating size
} else if (state === 4) {
this.size = this.baseSize + random(-3, 3); // Disoriented: Irregular size
} else {
this.size = this.baseSize;
}
}
show(state) {
noStroke();
if (state === 0) {
fill(0, 150, 255, 200); // Calm - blue
} else if (state === 1) {
fill(255, 100, 100, 200); // Anxious - red
} else if (state === 2) {
fill(random(200, 255), random(100, 200), random(150, 255), 200); // Euphoric - dynamic
} else if (state === 3) {
fill(50, 255, 50, 200); // Focused - green
} else if (state === 4) {
fill(random(100, 255), random(100, 255), 0, 200); // Disoriented - yellow and jittery
}
ellipse(this.x, this.y, this.size);
}
}
// Connection class represents edges between nodes
class Connection {
constructor(nodeA, nodeB) {
this.nodeA = nodeA;
this.nodeB = nodeB;
this.weight = random(0.2, 1);
}
show(state) {
let alpha = map(noise(t * this.weight), 0, 1, 50, 200);
if (state === 0) {
stroke(0, 100, 200, alpha); // Calm - blue
strokeWeight(1);
} else if (state === 1) {
stroke(200, 50, 50, alpha); // Anxious - red
strokeWeight(2 + sin(t * 10) * 1); // Jittery connections
} else if (state === 2) {
stroke(random(200, 255), random(100, 200), random(150, 255), alpha); // Euphoric - colorful
strokeWeight(1);
} else if (state === 3) {
stroke(50, 200, 50, alpha); // Focused - green
strokeWeight(1.5); // Steady connections
} else if (state === 4) {
stroke(random(200, 255), random(200, 255), 0, alpha); // Disoriented - flickering
strokeWeight(random(1, 3)); // Chaotic connection weight
}
line(this.nodeA.x, this.nodeA.y, this.nodeB.x, this.nodeB.y);
}
}
// Change states with key presses
function keyPressed() {
if (key === '1') state = 0; // Calm
if (key === '2') state = 1; // Anxious
if (key === '3') state = 2; // Euphoric
if (key === '4') state = 3; // Focused
if (key === '5') state = 4; // Disoriented
}