/* * Falling SnowFlakes * by Michael Shaub. * Lots of programming help from work by Daniel Shiffman */ // Simple Falling flake class class Flake { float x; float y; float speed; float gravity; float w; float life = 255; int j = 0; float rev = 0; Flake(float tempX, float tempY, float tempW, float RevDir) { x = tempX; y = tempY; w = tempW; speed = 0; gravity = 0.05; rev = RevDir; } void move() { // Add gravity to speed speed = speed + gravity; // Add speed to y location y = y + speed; // If square reaches the bottom // Bottom Edge if (y > (height+w*2)) { x = x + random(0,width); // move to the right if (x > width) { //tests for off-screen x = x - width; //resets position to the left } speed = speed/3; //slows the repeat's speed w = w/2; //halves the diameter y = 0-w*2; //resets the position off-screen to the top } } boolean finished() { // Flakes fade out life = life - 0.3; if (life < 0) { return true; } else { return false; } } void display() { //display the falling flakes pushMatrix(); //save regular location of the origin point (0,0) translate(x,y); //move (0,0) to new place if (rev < 0) { rotate(PI/(speed+1)*(1-2)); //spins the flakes clockwise }else{ rotate(PI/(speed+1)); //spins the flakes counterclockwise } scale(w/48); //scales coordinates to scale the flake stroke(193,201,235,(life/2)); //sets color to light blue w/alpha less over time // Draws the snowflake! for(int i = 0; i < 3; i++) { k1.render(); //draw 1 side rotate(2*PI/3); //rotate x,y around origin 120degrees } popMatrix(); //restore regular location of the origin point (0,0) and rotation of x,y //Grow the Crystal if (k1.getCount() < 4) { delay(800-j*30); //Show growth // Iterate k1.nextLevel(); j++; } } }