Thursday, September 24, 2009

Fangs is Back - Assignment for 2nd Week of ICM

For the second week of ICM we were tasked with creating a sketch that animates by leveraging conditional and loop statements, together with variables. I took this a few steps further by incorporating arrays, functions, objects, and (and even a photosensor computing sensor).

Though I had no experience writing software using an object oriented language, I had a theoretical understanding of this type of structure. In high school (longer ago then I care to remember), I wrote a paper about the principles of object oriented programming (OOP). This was during my senior year. I was happy to finally truly understand the power of this type of programming.

The latest version of the fangs sketch has the following features: a bat pointer follows the mouse around the screen. When that mouse button is pressed new bats are created. The right and left arrow keys enable the user to rotate the bats in either direction (though this feature is still not working perfectly). The eyes of the bats move around so that they are always looking towards the center. Finally, I created a sleep mode were all the bats perch themselves at the top of the window. The up and down buttons enable the user to enter and exit the sleep mode.



I encountered a lot of challenges when working on this project.

To be able to replicate the bats I defined a bat class that encapsulate all the attributes and behavior of the bat. Then I wrote code that creates individual instances of bats that are dynamically added to an array of bats (so that they can be easily managed). The bat class includes many methods/functions, including ones that randomly move the bat or move bat according to specific coordinates, that rotate bats in either direction, that transition bats into sleep mode, and that display all the bats.

To rotate the bats I had to learn how to use the pop/pushMatrix, translation, and rotation functions. This was one of the hardest obstacles I faced during the development of this sketch. However, once I learned how to use these capabilities I rewrote a lot of the code so that I could use them for all bat movements within my sketch (originally I considered using to pull of the rotation only).

The last tough challenge I had to overcome was associated to the sleep mode. Getting the bats to rotate properly and stop at the right location and rotation took some work. Originally I had planned to create only two states to govern this transition (sleep, awake), however, I realized that I need to create a third state (launch) so that the bats could properly rotate back to being right side up. I also had to find a solution to make the bats eyes closed once they had reached the top.

Check out my code on the openprocessing website. Let me know if you have any questions.

No comments: