• KJ Ha

Nature of Code: 3rd Assignment

Code

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

Live Sketch



Recent Posts

See All

Nature of Code: 2nd Assignment

Code For the second assignment, I've decided to develop the first assignment further. Besides using the createVector() function, for a more dynamic visual effect, I played with the alpha value of the

© 2020 Kyungjoo Ha. All Rights Reserved