Practice 3.5: Snowfall
Make a program that uses an array of objects to make animated snowfall

REQUIREMENTS

STEP BY STEP

Part A - Simple Snowflake Class


class Snowflake // This means we're defining a class - like we did with Robots!

{

   float x; // This is the data belonging to the class

   float y; // Every snowflake has its own x and y position

   

   Snowflake() // This is the constructor.  It's called when the object is made.

   { // Think of it like the setup() for each object.

     x = random(width);

     y = random(height);

   }

   

   void render() // This method is called render().  That's just a programming word

   { // that refers to drawing stuff on the screen.

     fill(255);
    ellipse(x, y, 10, 10); // Later on we'll add another method to handle movement.

   } 

}

Right click on the triangle next to the tabs to make a new tab.



Your project isn't ready to run yet!  Let's add some basic code to main to get it started.


Part B - A Single Snowflake


   Snowflake tempSnow; // This declares a single snowflake

   tempSnow = new Snowflake(); // This calls the Snowflake constructor, initializing it


    tempSnow.render(); // This calls the Snowflake's render method

Your program should show a blue background.  Make sure the array is both declared and initialized!

This seems like a lot of work to just get a single ellipse!  I know!  But trust me, the magic is about to happen. 
We're going to change it to use an Array and then we'll add in some movement.  Be patient.

Part C - Using An Array of Objects



Snowflake tempSnow

Snowflake[] snowflakes;


void setup()

{

  size(800, 600);

   

  tempSnow = new Snowflake 

  snowflakes = new Snowflake[500];

  

  for(int i = 0; i < snowflakes.length; i++)

  {

    snowflakes[i] = new Snowflake();

  }

  

}


void draw()

{

  background(80, 140, 255);

  

snow.render();

  for(int i = 0; i < snowflakes.length; i++)

  {

     snowflakes[i].render();

  }

  

}








Now we are showing 500 snowflakes.  They're not moving yet.  We're going to add that in with the next step.


Since we're using a class, we can have them be different in many ways - they won't just move vertically like we did in the Bubbles project.

Part C - Simple Movement



  for(int i = 0; i < snowflakes.length; i++)

  {

     snowflakes[i].update();

     snowflakes[i].render();

  }


Your bubbles should be moving downward and wrapping.  They may be moving sideways too!

Part D - More Data!


Snowflakes should move downward and to the right or left at different speeds.  Every snowflake should be a different size.

EXPANSION IDEAS