/** * Happy Holidays from M1ke + Z0w! * These season inspired forms are fractal curves called Koch Curves.
* Click the mouse to add more snowflakes.
*
* Falling SnowFlakes * by Michael Shaub.
* Lots of programming help from work by Daniel Shiffman */ ArrayList flakes; int flakeWidth = 48; float rev = 0; int counter = 0; int k = 0; int flip = 0; KochFractal k1; KochFractal k2; void setup() { size(800, 400); frameRate(30); smooth(); noStroke(); ellipseMode(CENTER); // Create an empty ArrayList flakes = new ArrayList(); //Create the SnowFlake k1 = new KochFractal(0, 0, 150); k2 = new KochFractal(0, 0, 150); // Start by adding one element flakes.add(new Flake(width/2, height/3, flakeWidth, 1)); } void draw() { background(41, 52, 97); // With an array, we say flakes.length, with an ArrayList, we say flakes.size() // The length of an ArrayList is dynamic // Notice how we are looping through the ArrayList backwards // This is because we are deleting elements from the list for (int i = flakes.size()-1; i >= 0; i--) { // An ArrayList doesn't know what it is storing so we have to cast the object coming out Flake flake = (Flake) flakes.get(i); flake.move(); flake.display(); if (flake.finished()) { // Items can be deleted with remove() flakes.remove(i); } } //Make a new flake every second if (counter < 120) { //count up to 1 sec counter++; //increment the counter in half seconds }else{ counter = 0; //resets the counter // A new flake object is added to the ArrayList (by default to the end) rev = random(-10,10); //spin direction rrandomizer flakes.add(new Flake(random(0,width), random(0,height), flakeWidth, rev)); //could add spin dir here } //Draw mouse pointer flake //strokeWeight(3); //hevier stoke weight for scaled down flake if (mouseX > 3 && mouseY > 3 && mouseX < width-3 && mouseY < height-3){ //Pulsing Circle at Cursor /* if (flip > 0) { fill(193,201,235,k*5); }else{ fill(193,201,235,(30-k)*5); } noStroke(); ellipse(mouseX, mouseY, 18, 18); stroke(193,201,235,255); */ pushMatrix(); //save regular location of the origin point (0,0) translate(mouseX,mouseY); //move (0,0) to new place rotate(radians(k*2)); //spins the flakes counterclockwise scale(.2); //scales coordinates to scale the flake stroke(193,201,235,255); //sets color to light blue // Draws the snowflake! pushMatrix(); //save rotation for(int i = 0; i < 3; i++) { k2.render(); //draw 1 side rotate(2*PI/3); //rotate x,y around origin 120degrees } popMatrix(); //restore regular rotation of x,y popMatrix(); //restore regular location of the origin point (0,0) //strokeWeight(1); //normal stroke weight //Grow the Crystal if (k < 30) { //count up to 1/2 sec k++; //increment the counter in half seconds }else{ k = 0; //resets the counter if (flip > 0) { flip = 0; }else{ flip = 1; } if (k2.getCount() < 3) { // Iterate k2.nextLevel(); }else{ k = 0; //resets the counter k2.restart(); } } } } void mousePressed() { // A new flake object is added to the ArrayList (by default to the end) rev = random(-10,10); flakes.add(new Flake(mouseX, mouseY, flakeWidth, rev)); //could add spin dir here counter = 0; //resets the counter }