Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week 16 Exercise #38

Open
Jeswing opened this issue Feb 10, 2016 · 6 comments
Open

Week 16 Exercise #38

Jeswing opened this issue Feb 10, 2016 · 6 comments
Labels

Comments

@Jeswing
Copy link

Jeswing commented Feb 10, 2016

No description provided.

@Jeswing
Copy link
Author

Jeswing commented Feb 10, 2016

Tab 1

Mover ball;
Mover ball3;
PVector wind= new PVector(.2, 0);

void setup(){
  size(600,600);
  ball= new Mover();
  ball3= new Mover();
}

void draw(){
  background(0);
  ball.update();
  ball.checkEdges();
  ball.display();
  ball3.update();
  ball3.checkEdges();
  ball3.display();

  if(mousePressed){
    ball.applyForce(wind);
    ball3.applyForce(wind);
  }

}

Tab 2

class Mover {
  PVector location;
  PVector velocity;
  PVector acceleration;
  float mass;

Mover(){
    location = new PVector(random(width),random(height));
    velocity = new PVector(random(-2,2),random(-2,2));
    acceleration = new PVector(0.001,-0.001);
    mass= random(1,2);
  }

  void applyForce(PVector force) {
    PVector f= PVector.div(force, mass);
    acceleration.add(f);
  }
  void display() {
    stroke(0);
    fill(255,0,255);
    ellipse(location.x, location.y, 20*mass, 20*mass);
  }

  void update() {
    velocity.add(acceleration);
    location.add(velocity);
    acceleration.mult(0);
  }

  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;
    }
  }
}

@GoHawks12
Copy link

Tab one

Mover ballone;

Mover balltwo;

PVector wind = new PVector(0.01, 0);

void setup(){
  size(400, 400);

  ballone = new Mover();

  balltwo = new Mover();
}

void draw(){
  background(118,117,0);
  ballone.display();
  ballone.update();
  ballone.checkEdges();
  balltwo.display();
  balltwo.update();
  balltwo.checkEdges();

  if(mousePressed);
  ballone.applyForce(wind);
  balltwo.applyForce(wind);
}

Tab two

class Mover{
  PVector location;
  PVector velocity;
  PVector acceleration;
  float mass;

  Mover(){
    location = new PVector(random(width), random(height));
    velocity = new PVector(0,0);
    acceleration = new PVector(0,0);
    mass = random(1,6);
  }

  void display(){
    stroke(0);
    fill(150,115,0);
    ellipse(location.x,location.y,20,20);
    velocity.add(acceleration);
    location.add(velocity);
    acceleration.mult(0);
  }

  void update(){
    velocity.add(acceleration);
    location.add(velocity);
  }

   void applyForce(PVector force){
    PVector f = PVector.div(force,mass);
    acceleration.add(f);
  }

  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;
    }
  }
}

@Brandonsugar
Copy link

Tab one:

Mover ball;
Mover ball2;

PVector wind = new PVector(5,0);

void setup(){
  size(1000,800);
  ball = new Mover();
  ball2 = new Mover();
}

void draw(){
  background(0);
  ball.display();
  ball.borders();
  ball.update();
  ball2.display();
  ball2.borders();
  ball2.update();

if(mousePressed){
  ball.applyForce(wind);
  ball2.applyForce(wind);
}
}

@Brandonsugar
Copy link

Tab two:

class Mover{
  PVector location;
  PVector velocity;
  PVector acceleration;
  float mass;

  Mover(){
    location = new PVector(random(width),random(height));
    velocity = new PVector(random(-2,2),random(-2,2));
    acceleration = new PVector(0,0);
    mass = random(1,6);
  }
  void display(){
    stroke(0);
    fill(200);
    ellipse(location.x,location.y,25*mass,25*mass);
  }
  void applyForce(PVector force){
    PVector f = PVector.div(force,mass);
    acceleration.add(f);
  }
  void update(){
    location.add(velocity);
    velocity.add(acceleration);
    acceleration.mult(0);
  }
  void borders(){
    if(location.x > width+12.5){
      velocity.x = velocity.x *-1;
    } else if(location.x < 12.5){
      velocity.x = velocity.x *-1;
    }
    if(location.y > height+12.5){
      velocity.y = velocity.y * -1;
    } else if(location.y < 12.5){
      velocity.y = velocity.y *-1;
    }
  }
}

@Pummelweed
Copy link

Tab 1

Mover ball;
Mover ball2;
PVector wind = new PVector(0.1,0);

void setup(){
  size(550,550);
  ball = new Mover();
  ball2 = new Mover();
}

void draw(){
  background(239,100,145);
  ball.update();
  ball.display();
  ball.checkEdges();
  ball2.update();
  ball2.display();
  ball2.checkEdges();

  if(mousePressed){
    ball.applyForce(wind);
  }
  if(mousePressed){
    ball2.applyForce(wind);
  }
  }

Tab 2

class Mover{
  PVector location;
  PVector velocity;
  PVector acceleration;
  float mass;

  Mover(){
    location = new PVector(random(width),random(height));
    velocity = new PVector(random(-2,2),random(-2,2));
    acceleration = new PVector(0,0);
    mass = random(1,2);
  }

  void applyForce(PVector force){
    PVector f = PVector.div(force,mass);
    acceleration.add(f);
  }

  void display(){
    noStroke();
    fill(255,0,50);
    ellipse(location.x,location.y,20,20);
  }

  void update(){
    velocity.add(acceleration);
    location.add(velocity);
    acceleration.mult(0);
  }

  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;
    }
  }
}

@Firefox99
Copy link

tab1

mover ball;
mover ball2;
PVector wind = new PVector (.2,0);

void setup(){
 size(400,400);
 ball= new mover();
 ball2= new mover();
}

void draw(){
 ball.update();
 ball.checkedges();
 ball.display();
 ball2.update();
 ball2.checkedges();
 ball2.display();
 if(mousePressed){
  ball.applyForce(wind); 
   ball2.applyForce(wind); 
 }
}

tab2

class Mover{
  PVector location;
  PVector velocity;
  PVector acceleration;

  Mover(){
    location = new PVector(random(width),random(height));
    velocity = new PVector(random(-2,2),random(-2,2));
    acceleration = new PVector(0.001,-0.001);
  }

  void display(){
    stroke(0);
    fill(150);
    ellipse(location.x,location.y,20,20);
  }

  void update(){
    velocity.add(acceleration);
    location.add(velocity);
  }

  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;
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants