import oscP5.*; import netP5.*; OscP5 oscP5; NetAddress myBroadcastLocation; Mover[] movers = new Mover[20]; int x_position = 200; int y_position = 200; int mouse_x_old, mouse_y_old; void setup() { size(400,400); smooth(); background(255); oscP5 = new OscP5(this,8000); myBroadcastLocation = new NetAddress("127.0.0.1",7000); for (int i = 0; i < movers.length; i++) { movers[i] = new Mover(); } mouse_x_old = mouseX; mouse_y_old = mouseY; } void draw() { noStroke(); fill(255,10); rect(0,0,width,height); for (int i = 0; i < movers.length; i++) { movers[i].update(); movers[i].checkEdges(); movers[i].display(); } mouse_check(); } void mouse_check() { if ((mouse_x_old == mouseX) && (mouse_y_old == mouseY) ) return; mouse_x_old = mouseX; mouse_y_old = mouseY; OscMessage myOscMessage = new OscMessage("Processing"); myOscMessage.add(mouse_x_old); myOscMessage.add(mouse_y_old); oscP5.send(myOscMessage, myBroadcastLocation); } void oscEvent(OscMessage theOscMessage) { x_position = theOscMessage.get(0).intValue(); y_position = theOscMessage.get(1).intValue(); } class Mover { PVector location; PVector velocity; PVector acceleration; float topspeed; Mover() { location = new PVector(random(width),random(height)); velocity = new PVector(0,0); topspeed = 4; } void update() { PVector mouse = new PVector(x_position,y_position); PVector dir = PVector.sub(mouse,location); dir.normalize(); // Normalize dir.mult(0.5); // Scale acceleration = dir; // Set to acceleration velocity.add(acceleration); velocity.limit(topspeed); location.add(velocity); } void display() { stroke(0); fill(175); ellipse(location.x,location.y,16,16); } void checkEdges() { if (location.x > width) { location.x = 0; } else if (location.x < 0) { location.x = width; } if (location.y > height) { location.y = 0; } else if (location.y < 0) { location.y = height; } } }