Recitation6: Object Dancer

Title: Dancer

Link: https://editor.p5js.org/LafouCC/sketches/bmAqYDXa4

Description: This dancer actually looks a lot like the Inflatable Air Dancers. So basically I want to imitate a tiny guy waving his arm and dancing with his knees.

Video: 

 

Code Snippets:

how to make a sin wave that has a fixed length:

for (let x = 10; x < 45; x += 0.1) {
        this.armY = sin(x * 0.1 + frameCount * 0.1) * this.amp;
        point(x, this.armY);
      } 

Reflections:

  • What is the benefit of your class not relying on any code outside of its own definition?

it’s more modular, and it can be easily copied and used in other places.

  • What makes it challenging to write code that has to harmonize with the code other people have written?  

it is crucial not to declare variables outside of the class and maybe pay attention to the different methods that you create and see if they are called in the draw() function.

  • Describe the terms modularity and reusability using the example of your dancer class.

Modularity means the code can be broken down into independent pieces. For example, the code has a class named dancer which contains a constructor, an update() method and a display() method. So the large code consists of small building blocks.

Reusability means the code can be easily reused, repurposed, and copied. So the code mustn’t have a lot of variables outside of the class function.

Leave a Reply

Your email address will not be published. Required fields are marked *