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 17 Exercise #40

Open
chasestarr opened this issue Feb 17, 2016 · 5 comments
Open

Week 17 Exercise #40

chasestarr opened this issue Feb 17, 2016 · 5 comments
Labels

Comments

@chasestarr
Copy link
Member

Apply Force Mover Class

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 applyForce(PVector force){
    PVector f = PVector.div(force,mass);
    acceleration.add(f);
  }

  void display(){
    stroke(0);
    fill(150);
    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){
      velocity.x *= -1;
    } else if(location.x < 0){
      velocity.x *= -1;
    }

    if(location.y > height){
      velocity.y *= -1;
    } else if(location.y < 0){
      velocity.y *= -1;
    }
  }
}
@chasestarr
Copy link
Member Author

screenshot 2016-02-17 11 32 06

@Brandonsugar
Copy link

Tab 1;

Bouncing[] balls = new Bouncing[20];


PVector magnet = new PVector(0,-7);

void setup(){
  size(1000,800);
  for(int i=0; i<balls.length; i++){
    balls[i] = new Bouncing();
  }
  //ball = new Bouncing();
}

void draw(){
  background(200);
  for(int i=0;i<balls.length; i++){
    balls[i].display();
    balls[i].update();
    balls[i].borders();
    balls[i].gravity();


    PVector friction = balls[i].velocity.get();
    friction.normalize();
    friction.mult(-1);
    friction.mult(0.05);
    balls[i].applyForce(friction);

  if(mousePressed){
    balls[i].applyForce(magnet);
  }
  }
}

Tab 2;

class Bouncing{
  PVector location;
  PVector velocity;
  PVector acceleration;
  float mass;
  float gravity;

  Bouncing(){
    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);
    gravity = 0.98;
  }
  void display(){
    stroke(0);
    fill(0,200,0);
    ellipse(location.x,location.y,15*mass,15*mass);
  }
  void gravity(){
    velocity.y = velocity.y+gravity;
  }
  void applyForce(PVector force){
    PVector f = PVector.div(force,mass);
    acceleration.add(f);
  }
  void borders(){
    if(location.x < 7.5){
      velocity.x = velocity.x * -0.98;
    } else if(location.x > width-7.5){
      velocity.x = velocity.x * -0.98;
    }
    if(location.y < 57.5){
      velocity.y = velocity.y * -0.98;
    } else if(location.y > height-7.5){
      velocity.y = velocity.y *-0.98;
    }
  }
  void update(){
    location.add(velocity);
    velocity.add(acceleration);
    acceleration.mult(0);
  }
}

@The-Space-Core
Copy link

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

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

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

PVector friction = ball.velocity.get();
friction.normalize();
friction.mult(-1);
friction.mult(0.01);

ball.applyForce(friction);

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

@The-Space-Core
Copy link

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 applyForce(PVector force){
PVector f = PVector.div(force,mass);
acceleration.add(f);
}

void display(){
stroke(0);
fill(150);
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){
velocity.x *= -1;
} else if(location.x < 0){
velocity.x *= -1;
}

if(location.y > height){
  velocity.y *= -1;
} else if(location.y < 0){
  velocity.y *= -1;
}

}
}

@Firefox99
Copy link

TAB 1

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

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

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

 PVector friction = ball.velocity.get();
 friction.normalize();
 friction.mult(-1);
 friction.mult(3);

 ball.applyForce(friction);

 if(mousePressed){
  ball.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(0,0);
    acceleration = new PVector(0,0);
    mass = random(1,6);
  }

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

  void display(){
    stroke(0);
    fill(150);
    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){
      velocity.x *= -1;
    } else if(location.x < 0){
      velocity.x *= -1;
    }

    if(location.y > height){
      velocity.y *= -1;
    } else if(location.y < 0){
      velocity.y *= -1;
    }
  }
}

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

4 participants