MaxLink link = new MaxLink(this, "scatter"); // ** added for MaxLink
Mover[] movers = new Mover[2];
float x_report[]= new float[2];
float y_report[] = new float[2];
void setup() {
size(640,360);
for(int i = 0; i < movers.length; i++) {
movers[i]=new Mover(random(1,4),random(width),0);
}
}
void draw() {
background(255);
PVector wind = new PVector(0.001,0);
PVector gravity = new PVector(0,0.1);
for (int i =0; i < movers.length; i++){
float c = 0.01;
PVector friction = movers[i].velocity.get();
friction.mult(-1);
friction.normalize();
friction.mult(c);
movers[i].applyForce(friction);
movers[i].applyForce(wind);
movers[i].applyForce(gravity);
movers[i].update();
movers[i].display();
movers[i].checkEdges();
x_report[i] = movers[i].location.x; //this is where i'm trying to send the outputs as
// listed coordinates to max
y_report[i] = movers[i].location.y;
link.output(0,x_report[i]);
link.output(1,y_report[i]);
println(y_report[i]);
}
}
class Mover {
PVector location;
PVector velocity;
PVector acceleration;
float mass;
Mover(float m, float x, float y) {
mass = m;
location = new PVector(x,random(height/2));
velocity = new PVector(0,0);
acceleration = new PVector(0,0);
}
void applyForce(PVector force) {
PVector f = PVector.div(force,mass);
acceleration.add(f);
}
void update() {
velocity.add(acceleration);
location.add(velocity);
acceleration.mult(0);
}
void display() {
stroke(0);
strokeWeight(2);
fill(127);
ellipse(location.x,location.y,mass*16,mass*16);
}
void checkEdges() {
if (location.x > width) {
location.x = width;
velocity.x *= -1;
} else if (location.x < 0) {
velocity.x *= -1;
location.x = 0;
}
if (location.y > height) {
velocity.y *= -1;
location.y = height;
}
}
}