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 21 Exercise #46

Open
chasestarr opened this issue Apr 6, 2016 · 7 comments
Open

Week 21 Exercise #46

chasestarr opened this issue Apr 6, 2016 · 7 comments
Labels

Comments

@chasestarr
Copy link
Member

screenshot 2016-04-06 11 22 55

@chasestarr
Copy link
Member Author

link to mover: #42

@Brandonsugar
Copy link

Tab 1;

Mover m;
PVector gravity = new PVector(0.2,0.2);

void setup(){
  size(1000,1000);
  m = new Mover(300,0);
}

void draw(){
  background(255);
  m.display();
  m.checkEdges();
  m.update();
  m.applyForce(gravity);
}

@Brandonsugar
Copy link

Tab 2;

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

  Mover(float xLoc, float yLoc){
    location = new PVector(xLoc,yLoc);
    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(){
 float Theta = velocity.heading();
 stroke(0);
 pushMatrix();
 rectMode(CENTER);
 translate(location.x, location.y);
 rotate(Theta);
 rect(0,0,30,10);
 popMatrix();
  }

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

@The-Space-Core
Copy link

Mover ball;
PVector gravity = new PVector(0,0.2);

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

void draw(){
background(255);
fill(0,0,200);
rect(0,0,400,400);

ball.display();
ball.checkEdges();
ball.update();
ball.applyForce(gravity);

float c = 0.3;
float speed = ball.velocity.mag();
float dragMagnitude = c * speed * speed;
PVector drag = ball.velocity.get();
drag.mult(-1);
drag.normalize();
drag.mult(dragMagnitude);

if(ball.location.y > 200){
ball.applyForce(drag);
}
}

@The-Space-Core
Copy link

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

Mover(float xLoc, float yLoc){
location = new PVector(xLoc,yLoc);
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(){
float theta = velocity.heading();
stroke(0);
fill(150);
pushMatrix();
rectMode(CENTER);
translate(location.x,location.y);
rotate(theta);
rect(0,0,30,10);
ellipse(15,0,10,10);
popMatrix();
}

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

}
}

@GoHawks12
Copy link

Tab one

PVector velocity = new PVector(0, 01);


void display(){
  float theta = velocity.heading();
  stroke(0);
  fill(150);
  pushMatrix();
  rectMode(CENTER);
  rotate(theta);
  rect(0, 0, 30, 10);
  ellipse(15, 0, 10, 10);
  popMatrix();
}

Tab two

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

  Mover(float xLoc, float yLoc){
    location = new PVector(xLoc,yLoc);
    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);
     translate(location.x, location.y);
    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 m;

void setup(){
 size(500,500);
 m = new Mover(250,250);
}

void draw(){
  background(#15DAEA);
  m.display();
  m.checkEdges();
  m.update();

}

tab 2

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

  Mover(float xLoc, float yLoc){
    location = new PVector(xLoc,yLoc);
    velocity = new PVector(2,3);
    acceleration = new PVector(0,0);
    mass = random(1,6);
  }

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

  void display(){
    float theta = velocity.heading();
    stroke(0);
    fill(150);
   pushMatrix();
   rectMode(CENTER);
   translate(location.x,location.y);
   rotate(theta);
   rect(0,0,50,50);
   popMatrix();
  }

  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

5 participants