Recitation 11. Workshops by Frances (Fan Yuan)

Workshop: Object Oriented Programming with Tristan

In this workshop, we learned to build a class from scratch and to achieve more complicated functions.  For the exercise, I created a class called Snowflake and used this class to simulate snowing scenes. In the class, each snowflake has four variables: x, y coordinate positions, size, and falling speed. Point (x, y) is its center and I used three lines across it to create its shape. And I also create a function called fall to control its speed of falling.

Then, in order to use this class to simulate snowing, I created an ArrayList called snow. Every time the user clicks the mouse, new snowflakes will be added to this ArrayList and in draw loop they will be displayed. To make the scene more natural, I used random functions so that the snowflakes generated will be of random sizes, random speed and random positions around the mouse. Moreover, snowflakes won’t disappear from the screen, but stop when their y is equal to height, which stimulates snow’s accumulation on the ground.

Leave a Reply