Waving sausage dog
Description and Concept
In this project, I made a sausage dog that is waving his long body. His legs swing with his body movement. Meanwhile, his tongue and tail are shaking at a faster speed.
Coding
The most important part of my code is the waving body. With Leon’s help, I knew that making the curve start waving on the canvas was similar to moving a viewfinder through the sin wave. So how the values inside sin() matters a lot.
In this for loop, sin(0.03*i) only makes the curve up and down but in stillness. The “this.bodyOffset” is the viewfinder, which makes the wave start moving.
Reflection
- class
Compared with the previous way we code, in “class”, we put the global variable with “this.” before the “update” or “display”. we gather all the values that need to continuously change into “update”. The “display” is more like the draw loop, we call functions there.