//import com.hamoid.*; //VideoExport videoExport; //final String sketchname = getClass().getName(); //void rec() { // if (frameCount == 1) { // videoExport = new VideoExport(this, sketchname + random(1000000) + ".mp4"); // videoExport.setFrameRate(60); // videoExport.startMovie(); // } // videoExport.saveFrame(); //} int nodeMargin = 4; int nodesPerRow = 35; int rows = 35; ArrayList nodes = new ArrayList(); ArrayList attractors = new ArrayList(); void setup() { size(900, 900); background(0); stroke(255); int xInc = width / nodesPerRow; int yInc = height / rows; for (int i = nodeMargin; i <= rows - nodeMargin; i++) { for (int j = nodeMargin; j <= nodesPerRow - nodeMargin; j++) { nodes.add(new Node(new PVector(j*xInc, i*yInc))); } } attractors.add(new Attractor(new PVector(random(width), random(height)), 3.0)); attractors.add(new Attractor(new PVector(random(width), random(height)), 5.0)); attractors.add(new Attractor(new PVector(random(width), random(height)), 7.0)); attractors.add(new Attractor(new PVector(random(width), random(height)), 9.0)); } void draw() { background(0); fill(255); for (Attractor a : attractors) { a.move(); a.show(); } PVector force = new PVector(0, 0); for (Node n : nodes) { for (Attractor a : attractors) { force.add(a.calcForce(n)); } n.pos = n.origin.copy().add(force); force.setMag(0); } strokeWeight(5); for (Node n : nodes) { n.show(); } //println(frameCount / 60); println(frameRate); //rec(); } class Attractor { PVector pos; PVector vel; float maxMag; float radius; Attractor(PVector pos, float maxMag) { this.pos = pos; vel = new PVector(random(1, 3), random(1, 3)); this.maxMag = maxMag; radius = maxMag * 3; } PVector calcForce(Node n) { PVector force = n.pos.copy().sub(this.pos); PVector unit = force.copy().normalize(); float mag = force.mag(); return unit.mult(maxMag * 400.0 / mag); } void move() { pos.add(vel); if (pos.x < radius || pos.x > width - radius) { vel.x *= -1; } if (pos.y < radius || pos.y > height - radius) { vel.y *= -1; } } void show() { ellipse(pos.x, pos.y, radius, radius); } } class Node { PVector pos; PVector origin; Node(PVector pos) { this.pos = pos; this.origin = pos.copy(); } void force() { } void show() { strokeWeight(1); line(origin.x, origin.y, pos.x, pos.y); strokeWeight(5); point(pos.x, pos.y); } void reset() { this.pos = origin.copy(); } }