-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Tab 1;
Particle p;
PVector wind = new PVector(0.001,0);
void setup(){
size(1000,750);
p = new Particle(random(width),random(height));
}
void draw(){
background(200,200,255);
p.run();
p.applyForce(wind);
}
Tab 2;
class Particle{
PVector location;
PVector acceleration;
PVector velocity;
int lifeSpan;
Particle(float xLoc,float yLoc){
location = new PVector(xLoc,yLoc);
acceleration = new PVector();
velocity = new PVector();
lifeSpan = 255;
acceleration.mult(0);
}
void display(){
stroke(0,lifeSpan);
fill(175,lifeSpan);
ellipse(location.x,location.y,15,15);
}
void update(){
velocity.add(acceleration);
location.add(velocity);
lifeSpan -= 2;
}
void run(){
update();
display();
}
void applyForce(PVector f){
acceleration.add(f);
}
void borders(){
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;
}
}
}
Metadata
Metadata
Assignees
Labels
No labels