1. #creativePact Day 16

    #creativePact, just a quick update to yesterday’s patch - when using the gathering function (Right-Click), and moving the mouse, the balls get too close together and won’t separate. I’ve added a middle-click option which should help at separation when they get too close together. This is basically building up to using a gamepad (PS2/Logitech Wingman) to control the different functions and mouse position!

    Mover[] mover = new Mover[400];

    void setup() {

      size(640, 480);

      smooth();

      background(0);

      for (int i = 0; i < mover.length; i++) {

        mover[i] = new Mover();

      }

    }

    void draw() {

      background(180, 100, 180);

      for (int i = 0; i < mover.length; i++) {

        mover[i].update();

        mover[i].checkEdges();

        mover[i].display();

      }

    }

    class Mover {

      PVector location;

      PVector velocity;

      PVector acceleration;

      float topspeed;

      Mover() {

        location = new PVector(random(width), random(height));

        velocity = new PVector(0, 0);

        topspeed = 5;

      }

      void update() {

        PVector mouse = new PVector(mouseX, mouseY);

        PVector dir = PVector.sub(mouse, location);

        dir.normalize();

        if (mousePressed && (mouseButton == LEFT)) {

          dir.mult(0.000001);

        } else if (mousePressed && (mouseButton == RIGHT)) {

          dir.mult(1);

        } else if (mousePressed && (mouseButton == CENTER)) {

          dir.mult(5);

        } else {

          dir.mult(0.2);

        }

        acceleration = dir;

        velocity.add(acceleration);

        velocity.limit(topspeed);

        location.add(velocity);

      }

      void display() {

        stroke(location.x, location.y, location.y);

        fill(location.x, location.y, location.y);

        ellipse(location.x, location.y, 2, 2);

      }

      void checkEdges() {

        if ((location.x > width) || (location.x < 0)) {

          velocity.x = velocity.x * -1;

        } 

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

          velocity.y = velocity.y * -1;

        }

      }

    }