So this weeks ICM homework is supposed to include making our own functions / objects. In class we covered an example with raindrops, making the Raindrop a class, the functions that affect this class, and then implementing this class in a regular processing program. Using this example, I decided it would be a good idea to test out these ideas by making a snowstorm. This of course involved jumping ahead a bit, since in order to keep my code simple (and not copied a bazillion times for however many snowflakes I want) I used an array.
I created a class for the snowflake, and the object SnowFlake asks for all sorts of arguments in order to determine what type of snowflake it is (all ellipses, but size, starting location, and speed are all important).
In the snowstorm sketch, the program makes an array of SnowFlake objects (equal to the number selected with the variable numFlakes), and then creates all the snowflakes necessary. By adding random into key variables (starting y, x position while falling etc) the snow flakes coat the screen in a seemingly random (and realistic pattern). I also made it so that when the snowflakes hit the bottom of the screen, they are transported back to the top so it appears as if the snow goes on forever.
Simple enough in practice, but there is a lot of theory all combined together to make the code look smooth (arrays, variables, new objects and functions etc). For my next project I am going to take all of these tools I have learned to create a game either called “Cross Canal St” or “Driving on Canal St” since that will be a good way to use an array to display the traffic that I face everyday when I go to leave my apartment (thank goodness I don’t have a car).
The Snowstorm is available here.