Nature of Code HW#2 (Vectors and Forces)

NC 2 HW from Colin Narver on Vimeo.

This week's nature of code HW has me playing with the forces of gravity and antigravity simulated through a hot air balloon. Gravity is imposed upon the balloon with the key press of G and a mouse click imposes antigravity.  This may or may not be the environment I use to experiment with more forces in future projects. I like the idea of potentially having several hot air ballons being blown around by gusts of wind and each balloon having to navigate its course through large groups of flocking birds.

//Colin Narver
//Nature of Code

Mover mover;

//PVector current;

void setup() {
  size(600, 800, P2D);
  mover = new Mover();


void draw() {

  PVector gravity= new PVector (0, .015);
  PVector antiGravity = new PVector (0, -.015);

  if (mousePressed) {            //click the mouse to use antiGravity 
    println("MOUSE PRESSED");
  if (keyPressed) {      //press the key "g" to use gravity
    if (key == 'g') {

class Mover {

  PVector location;
  PVector velocity; //speed
  PVector acceleration; //the rate at which that speed is being applied 
  PVector gravity;
  PShape s;  
  PImage img;

  Mover() {
      s = loadShape("balloon.svg");
      img = loadImage("clouds.jpeg");

    location= new PVector (width/2-50, height/2-50);
    velocity= new PVector (0, 0);      //ball starts from a stop
    acceleration= new PVector (0, 0);  //ball accelerates downward as Y values increases perpetually
    //antiGravity= new PVector (0, -.01);

  void run() {

  println("Acc: " + acceleration);
  println("Vel: " + velocity);
  println("Loc: " + location);

void update() {

    location.add(velocity);  //velocity changes by acceleration
    acceleration.mult(0);  //if acceleration is steady on, velocity will continue to ramp up  and location will fly 


  void display() {
//    stroke(255, 0, 0);
//    fill(0, 0, 255);
    image(img, 0,0);     //clouds
    shape(s, location.x, location.y, 125, 125);     //hot air balloon

  void applyForce(PVector forceBeingApplied) {    //the constructor of the function 

  void checkEdges() {
    if (location.x> width) {
    else if (location.x< 0) {

    if (location.y> height) {
    else if (location.y<0) {