ArrayList nodes; int init_count = 500; float attractor_radius = 200; void setup() { size(720, 720); colorMode(HSB, 360, 100, 100, 100); background(33); nodes = new ArrayList(); initNodes(); } void initNodes() { nodes.clear(); for (int i = 0; i < init_count; i++) { nodes.add(new Node()); } } void draw() { background(33); for (Node n : nodes) { n.update(); n.show(); } } class Node { PVector position; color fillcolor; PVector velocity; float rad; float shift; Node() { position = new PVector(); position.x = random(width); position.y = random(height); fillcolor = color(random(160, 200), random(80, 100), 100, 80); velocity = new PVector(); velocity.x = random(-3, 3); velocity.y = random(-2, 2); rad = 5; shift = random(TWO_PI); } void update() { PVector at_force = new PVector(); float distance = dist(mouseX, mouseY, position.x, position.y); if (distance < attractor_radius) { float mag = map(distance, 0, attractor_radius, 0.2, 0); at_force = PVector.sub(new PVector(mouseX, mouseY), position); at_force.mult(mag); //velocity.mult(mag); } position.add(velocity); position.add(at_force); if (position.x > width || position.x < 0) { velocity.x *= -1; } if (position.y > height || position.y < 0) { velocity.y *= -1; } rad = map(sin((frameCount / 10.0) + shift), -1, 1, 1, 10); } void show() { noStroke(); fill(fillcolor); ellipse(position.x, position.y, rad, rad); } }