Open chasestarr opened 8 years ago
Mr chase tell me if this is what you want.
Mover[] ball;
void setup(){ size(800,800); ball = new Mover[20]; for (int i = 0; i < ball.length; i++){ ball[i] = new Mover(); println("index"+i + " is " +ball[i]); } }
void draw(){ background(0);
for (Mover m : ball) {
PVector gravity = new PVector(0,0.01,10); m.applyForce(gravity);
if(mousePressed){ PVector wind = new PVector(0.02,0); m.applyForce(wind); } m.update(); m.display(); m.checkEdges();
} }
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); ellipse(location.x,location.y,20,20); float[]nums=new float[50];
}
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; } } }
@The-Space-Core looks good!
Thank you.
Tab one
Mover[] ball;
void setup(){
size(800, 800);
ball = new Mover[20];
for (int i = 0; i<ball.length; i++){
ball[i] = new Mover();
println("index"+i + " is " +ball[i]);
}
}
void draw(){
background(0);
for(Mover a: ball){
PVector gravity = new PVector(0,0.01,10);
a.applyForce(gravity);
if(mousePressed){
PVector wind = new PVector(0,0.01,10);
a.applyForce(wind);
}
a.update();
a.display();
a.checkEdges();
}
}
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(110, 115, 0);
ellipse(location.x, location.y, 30, 30);
float[]nums=new float[50];
}
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;
}
}
}
We're downstairs waiting for someone to open the door.
Sent from my Verizon Wireless 4G LTE smartphone
-------- Original message -------- From: Chase Starr notifications@github.com Date: 02/13/2016 3:37 PM (GMT-05:00) To: mositech/CS2015 CS2015@noreply.github.com Cc: The-Space-Core rbrusse@hotmail.com Subject: Re: [CS2015] HW #17 (#39)
@The-Space-Core looks good!
— Reply to this email directly or view it on GitHub.
_In this homework we will practice applying forces. Look at these three videos to go over forces again. Here is a link to the basic mover class if you need it._
Create at least 20 objects with mass on the screen that are constantly affected by a gravity force. When the mouse is pressed down, a secondary force will be applied to the objects. You will need to use for loops to complete this homework. Take a look at week16 image notes here
Please paste your code as a comment on this post