Project Title: Dancing Kitten 🎵
Link to the project: github
Brief Description & Concept
I make a kitten that can interact with music. When the music plays, the kitten will shake its head and tail in time with the rhythm, and may even make some movements of its hands and feet when the rhythm is strong, as if it is also a dancer dancing to the melody of the music. 🎶
Visual Documentation
Coding
In my project, there are many places where I want to create oscillating effects, so I use the ‘sin()’ function a lot because its values oscillate between -1 and 1. I embed the relevant property into the position coordinates of the rectangle, thereby creating the effect of the feet moving back and forth.
To create the effect of the tail, I introduced four properties respectively representing the swing angle, length, width, and curvature of the tail.
Reflection
- What is the benefit of your class not relying on any code outside of its own definition?
By not relying on any external code, I can have full control over behavior and functionality of the class, which makes the code easier to understand and debug, while also avoid being influenced by other code, thereby reducing potential errors. Putting everything about an object in one single class also makes the information more intuitive. All information related to this object can be found in this class, which greatly facilitates programming.
- What make it challenging to write code that has to harmonize with the code other people have written?
One problem that comes to my mind is that when different blocks of code are merged together, variable names often get duplicated and may affect the normal operation of the code. Even if the variable names are not repeated, a large number of variables can be confusing. In addition, there may be differences in coding styles and habits among different people, affecting the consistency of the code.
- Describe the terms modularity and reusability using the example of your dancer class.
In the context of the dancer class, I think modularity refers to dividing the code into independent modules or components (class), each with its specific function. For example, we can put different dancer behaviors and reactions (such as head shaking, tail wagging, limb movement) into separate functions, allowing each one to be independently modified and extended without affecting other behaviors or overall functionality.
Speaking of reusability, we can create classes that can be applied across various instances of dancers. If we want to achieve similar effects, we can also reuse the existing method from the dancer class without having to rewrite or duplicate code, which promotes code efficiency and simplify the code.
Leave a Reply