top of page

Falling Leaf Class

Omg!!! I did it!!!





The scene that I imagined for the creative code assignment was an array of leaves in different colors and sizes falling down to create an autumnal scene. The leaves would generate a random x position and begin above the screen and drop down. Ideally, they would also stop at a point at the bottom of the canvas and pile up to make one big leaf pile.


I tried coding this into a function but was having trouble calling the random value for the x position. The way that I had coded it, the random x value was constantly being called and the leaves were all over the place. I had to figure out how to call the random x position once and keep it for its leaf object.


I did some research to look for any tips or hints for direction. I thought "what if there was a setup function within the new function? Then I can call the random value only once! Actually, the first video I watched was a Snowflake Challenge that used classes that were in the videos I missed! The Snowflake Challenge video was everything I wanted to do, but I just didn't know how to construct classes at that point. Then I watched the Coding Train videos for this week's assignment on constructing classes and they answered all of my questions!!!


So I used classes and constructors to fashion my falling leaf scene :) I also added a bit of horizontal and vertical "jitter" to make them look like real falling leaves. I can definitely also add a bunch of different leaf colors but I'm tired now.


See the sketch here




20 views1 comment

Recent Posts

See All
bottom of page