/* In this example we have a single object moving around a single attractor object. Think of this like a planet orbiting the sun. */ // Our simulation object SimObject so; // Our object exerting gravitational pull Attractor att; // Flag for showing the force vectors boolean showVectors = true; // Font for labeling vectors PFont labelFont; void setup() { size(400, 400); background(15); // setup our sim object Vector2D a = new Vector2D(0.0, 0.0); Vector2D v = new Vector2D(0.0, -0.2); Vector2D l = new Vector2D(350, 350); so = new SimObject(l, v, a, 10); //so.setContained(true); // setup the attractor att = new Attractor(new Vector2D(width / 2, height / 2), 10, 0.2); // load our font labelFont = loadFont("LucidaGrande-32.vlw"); textFont(labelFont, 16); } void draw() { background(15); // figure out the force exerted on our SimObject by the attractor Vector2D attForce = att.getGravityForce(so); // add the forces to our object so.addForce(attForce); drawOverlay(so.getVelocity(), so.getLocation(), 50, "Velocity"); drawOverlay(so.getAcceleration(), so.getLocation(), 5000, "Acceleration"); // println("Velocity: " + so.getVelocity().getX() + ", " + so.getVelocity().getY()); // let the objects run so.simulate(); att.simulate(); } void mousePressed() { att.clicked(mouseX, mouseY); } void mouseReleased() { att.stopDragging(); } void keyPressed() { showVectors = !showVectors; }