top of page
  • Writer's pictureKJ Ha

Nature of Code: 3rd Assignment

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));

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;

Live Sketch

Recent Posts

See All

Nature of Code: Final Proposal

Link to video recording: For the final, I would like to continue working on the mid-semester exercise. (link to mid-semester exercise:


bottom of page