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

HW #19 #43

Open
chasestarr opened this issue Mar 2, 2016 · 9 comments
Open

HW #19 #43

chasestarr opened this issue Mar 2, 2016 · 9 comments
Labels

Comments

@chasestarr
Copy link
Member

In this homework we will practice applying friction. Look at this video to get a refresher on friction. Grab the newest mover class from here.

Create 4 different colored rectangles in the pattern of the image below. If your object is within one of these quadrants, apply a unique drag force. The mover object should randomly spawn anywhere along the x-axis and at y = 100. When the mover is above the liquid, apply a wind force in either a constant direction, or a random direction. Take a look at the image below.

_Please paste your code as a comment on this post_

06_hw

@The-Space-Core
Copy link

Can I copy and paste fragments of my previous projects?

@chasestarr
Copy link
Member Author

I recommend typing everything out, but yes - basing your homework on previous projects is fine.

@The-Space-Core
Copy link

Thank you.

@Brandonsugar
Copy link

@The-Space-Core
Copy link

Boat wheel;
PVector gravity = new PVector(0,0.98);
PVector wind = new PVector(0.7,0);
void setup(){
size(800,400);
wheel = new Boat(random(width),100);
}
void draw(){
background(255);
wheel.update();
wheel.checkEdges();
wheel.display();
wheel.applyForce(gravity);

//top

noFill();
rect(0,0,800,200);
if(wheel.location.y<=200){
wheel.applyForce(wind);
}

//bottom left

rect(0,200,200,200);
if(wheel.location.x < width/4 && wheel.location.y > height/2){
float c = 0.1;
float speed = wheel.velocity.mag();
float dragMagnitude = c_speed_speed;
PVector drag = wheel.velocity.get();
drag.mult(-1);
drag.normalize();
drag.normalize();
drag.mult(dragMagnitude);
wheel.applyForce(drag);
}

//bottom left center
rect(200,200,200,200);
if(wheel.location.x > width/4 && wheel.location.y > height/2 && wheel.location.x < width/2){
float c = 0.3;
float speed = wheel.velocity.mag();
float dragMagnitude = c_speed_speed;
PVector drag = wheel.velocity.get();
drag.mult(-1);
drag.normalize();
drag.normalize();
drag.mult(dragMagnitude);
wheel.applyForce(drag);
}

//bottom right center
rect(400,200,200,200);
if(wheel.location.x > width/2 && wheel.location.y>height/2 && wheel.location.x < 600){
float c = 0.2;
float speed = wheel.velocity.mag();
float dragMagnitude = c_speed_speed;
PVector drag = wheel.velocity.get();
drag.mult(-1);
drag.normalize();
drag.normalize();
drag.mult(dragMagnitude);
wheel.applyForce(drag);
}

//bottom right
rect(600,200,200,200);
if(wheel.location.x>600 && wheel.location.y>height/2 && wheel.location.x < width){
float c = 0.09;
float speed = wheel.velocity.mag();
float dragMagnitude = c_speed_speed;
PVector drag = wheel.velocity.get();
drag.mult(-1);
drag.normalize();
drag.normalize();
drag.mult(dragMagnitude);
wheel.applyForce(drag);
}
}

@The-Space-Core
Copy link

class Boat{
  PVector location;
  PVector velocity;
  PVector acceleration;
  float mass;
  Boat(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);
  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 = velocity.x*-1;
  } else if(location.x < 0){
    velocity.x = velocity.x*-1;
  }
  if(location.y > height){
    velocity.y = velocity.y*-1;
  } else if(location.y < 0){
    velocity.y = velocity.y*-1;


  }
}
}

@GoHawks12
Copy link

Tab one

Mover Pool;
PVector wind = new PVector(0,0.001);
PVector gravity = new PVector(0,0.98);


void setup(){
  size(800, 400);
  Pool = new Mover(random(width),100);
}

void draw(){

  background(255);

  fill(50,115,255);
  rect(0,height/2,width/4,height/2);
  fill(255,100,75);
  rect(width/4,height/2,width/4,height/2);
  fill(0,255,100);
  rect(width/2,height/2,width/4,height/2);
  fill(110,240,117);
  rect(750,height/2,width/4,height/2);
  fill(255,255,117);
  rect(0,0,width/4,height/2);
  rect(width/4,0,width/4,height/2);
  rect(width/2,0,width/4,height/2);
  rect(750,0,width/4,height/2);

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



  if(Pool.location.y < height/2){
    Pool.applyForce(wind);
  }

  if(Pool.location.x < width/4 && Pool.location.y > height/2){

  float a = 0.10;
  float speed = Pool.velocity.mag();
  float dragMagnitude = a * speed * speed;
  PVector drag = Pool.velocity.get();
  drag.mult(-1);
  drag.normalize();
  drag.normalize();
  drag.mult(dragMagnitude);
  Pool.applyForce(drag);
  }
  if(Pool.location.x < width/2 && Pool.location.y > height/2 && Pool.location.x > width/4){

   float a = random(0,0.5);
  float speed = Pool.velocity.mag();
  float dragMagnitude = a * speed * speed;
  PVector drag = Pool.velocity.get();
  drag.mult(-1);
  drag.normalize();
  drag.normalize();
  drag.mult(dragMagnitude);
  Pool.applyForce(drag);
  }
  if(Pool.location.x > width/2 && Pool.location.x < 750 && Pool.location.y > height/2){

      float a = 0.04;
  float speed = Pool.velocity.mag();
  float dragMagnitude = a * speed * speed;
  PVector drag = Pool.velocity.get();
  drag.mult(-1);
  drag.normalize();
  drag.normalize();
  drag.mult(dragMagnitude);
  Pool.applyForce(drag);
  }
  if(Pool.location.x > 750 && Pool.location.x < width && Pool.location.y > height/2){

      float a = 0.8;
  float speed = Pool.velocity.mag();
  float dragMagnitude = a * speed * speed;
  PVector drag = Pool.velocity.get();
  drag.mult(-1);
  drag.normalize();
  drag.normalize();
  drag.mult(dragMagnitude);
  Pool.applyForce(drag);
  }
}

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);
    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 chasestarr mentioned this issue Mar 9, 2016
@Firefox99
Copy link

tab one

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

void setup(){
size(800,400);
ball =new Mover(random(0,width),50);
}

void draw(){
background(255);
stroke(0);
fill(2, 178,237);
rect(0,200,200,200);
fill(120,3,173);
rect(200,200,200,200);
fill(22,245,22);
rect(400,200,200,200);
fill(245,22,100);
rect(600,200,200,200);

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

if(ball.location.x == width || ball.location.y >200){
  ball.applyForce(wind);
}

if(ball.location.x<200&&ball.location.y>200){
  float c = 0.001;
  float speed = ball.velocity.mag();
  float dragMagnitude = c * speed *speed;
  PVector drag = ball.velocity.get();
  drag.mult(-1);
  drag.normalize();
  drag.mult(dragMagnitude);
  ball.applyForce(drag);
}
if(ball.location.x>200&& ball.location.x<400&&ball.location.y>200){
  float c = 0.0036;
  float speed = ball.velocity.mag();
  float dragMagnitude = c * speed *speed;
  PVector drag = ball.velocity.get();
  drag.mult(-1);
  drag.normalize();
  drag.mult(dragMagnitude);
  ball.applyForce(drag);
}
if(ball.location.x>400&&ball.location.x<600&&ball.location.y>200){
  float c = 0.04;
  float speed = ball.velocity.mag();
  float dragMagnitude = c * speed *speed;
  PVector drag = ball.velocity.get();
  drag.mult(-1);
  drag.normalize();
  drag.mult(dragMagnitude);
  ball.applyForce(drag);
}
if(ball.location.x>600&&ball.location.x<800&&ball.location.y>200){
  float c = 0.4;
  float speed = ball.velocity.mag();
  float dragMagnitude = c * speed *speed;
  PVector drag = ball.velocity.get();
  drag.mult(-1);
  drag.normalize();
  drag.mult(dragMagnitude);
  ball.applyForce(drag);
}

}

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

  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

@Firefox99 👍

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