This week we learned about class and defining our own functions 🙂
https://editor.p5js.org/yyyyyelena/sketches/ucOLeBJ6G
- What is the benefit of your class not relying on any code outside of its own definition?
- Using class makes everything really clean and straight to the point. I put my codes in “update()” after I have constructed my dancer, so the whole coding logic makes more sense. I put the color changing of my dancer within the display() function because I am employing the for loop here, and it might be too much for me to process for loop with update.
- Since the color changing of the dancer is closely related to the position of the dancer’s body, putting it within the display will secure the color changing moves with the dancer. (( I figured it out by putting the for loop into update & display and trying out the result, so I guess that’s another benefit of using class?
- What make it challenging to write code that has to harmonize with the code other people have written?
- If I change the position of my dancer in the setup function, it wouldn’t bounce back again (easily)!!! But if I use variables to refer back to the location, it can’t be “let STARTX = startX”, because the editor shows that the variable startX is not defined in the current scope. I need to put the variable before “ dancer = new YelenaDancer(width/2,height/2);” ((which I think is not allowed (??
- Describe the terms modularity and reusability using the example of your dancer class.
- [this is what I discovered during the documentation process] by defining different functions on my own, the whole code looks soooo clean and it is much easier for me to detect errors!!
Leave a Reply