To introduce objects and eventually arraylists in Computer Programming, we made some snowflakes. I don’t even want to think how you would accomplish 1000 snowflakes like this without using objects or arrays….

IMG_2829 IMG_2828

If you’re looking for the code, here you go!
or

ArrayList snowflakes;

void setup(){
  size(800,800);
  background(120);
  snowflakes = new ArrayList();
  int count = 0;
  while (count < 100){
    Snowflake s = new Snowflake(random(width), 0, random(1,5), 7);
    snowflakes.add(s);
    count = count + 1;
  }  
}
void draw(){
  background(120);
  
  int count = 0;
  while (count < snowflakes.size()){ Snowflake s = snowflakes.get(count); s.updatePosition(); s.drawSnowflake(); count = count + 1; } } class Snowflake{ float xpos,ypos,speed,size; color c; Snowflake(float x, float y, float speed_t, float size_t){ xpos = x; ypos = y; speed = speed_t; size = size_t; c = color(255); } void updatePosition(){ ypos = ypos + speed; if (ypos > height){
      ypos = 0;
    }
  }
  
  void drawSnowflake(){
    fill(c);
    noStroke();
    ellipse(xpos, ypos, size, size);
  }
}

January 13, 2016

Leave a Reply