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 #16 #36

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

HW #16 #36

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

Comments

@chasestarr
Copy link
Member

In this homework we will practice applying forces. Look at these two videos to go over forces again. Here is a link to the basic mover class if you need it.

Simulate a helium filled balloon. Using the mousePressed code activate a wind force - so that when the mouse is pressed down, the balloon blows to the side.

Please paste your code as a comment on this post

@The-Space-Core
Copy link

PVector wind = new PVector(0.02,0);
PVector gravity = new PVector(0,-0.005,10);
void setup(){
size(800,800);
ball = new Mover();
}

void draw(){
background(0,200,255);
ball.update();
ball.display();
ball.checkEdges();
ball.applyForce(gravity);

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

}
}

@The-Space-Core
Copy link

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(245,240,155);
ellipse(location.x,location.y,250,50);
//bands
fill(255,0,0);
rect(location.x,location.y-25,1,50);
rect(location.x+25,location.y-25,1,50);
rect(location.x-25,location.y-25,1,50);
rect(location.x-50,location.y-22,1,45);
rect(location.x-75,location.y-20,1,40);
rect(location.x-100,location.y-14,1,29);
rect(location.x+50,location.y-22,1,45);
rect(location.x+75,location.y-20,1,40);
rect(location.x+100,location.y-14,1,29);
fill(255,0,0);
rect(location.x+50,location.y+18,25,15);
fill(0);
rect(location.x+65,location.y+23,10,5);
fill(255);
rect(location.x+65,location.y+23,4,2);
}

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

}
void applyForce(PVector force){
acceleration.add(force);
}
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 balloon;
PVector wind = new PVector(0, 0.02);
PVector gravity = new PVector(0.04, 12);

void setup(){
size(800, 800);
balloon = new mover();
}

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

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

Tab two

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(255,0,0);
    ellipse(location.x,location.y,20,20);
 }

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

 void applyForce(PVector force){
   acceleration.add(force);
 }

  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

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