For the second assignment, I've decided to simulate a helium-filled balloon. Since helium is known to be lighter than the other gases, I dismissed the force of gravity. Instead of disregarding the force of gravity, I've added a new force, helium, in the sketch as shown below.
let helium = createVector(0, random(-0.01, -0.05));
mover.applyForce(helium);
The rest hasn't changed much from the coding train example, Simulating Forces. The modification was added to deal with the occasion when the balloon hits the top of the sketch.
edges() {
if (this.pos.y <= this.r) {
this.vel.y *= -0.75;
this.pos.y = this.r;
}
if (this.pos.x >= width - this.r) {
this.pos.x = width - this.r;
this.vel.x *= -1;
this.pos.x = width - this.r;
} else if (this.pos.x <= this.r) {
this.pos.x = this.r;
this.vel.x *= -1;
}
}
Comments