Created
November 20, 2018 02:37
-
-
Save skrekhere/f8d1a61298d525424109b7120c3da974 to your computer and use it in GitHub Desktop.
snow but mine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
snowflake[] snowflakes; | |
snowflake snowflake; | |
float wind = 4.0; | |
int snowAmount; | |
void setup(){ | |
size(600,400); | |
background(0); | |
snowAmount = 400; | |
snowflakes = new snowflake[snowAmount]; | |
for(int i = 0; i < snowflakes.length; i++){ | |
float size = (abs(round(randomGaussian()))*(round(random(0.6)*10)+0.1)); | |
snowflakes[i] = new snowflake(random(width), random(height), size); | |
} | |
noStroke(); | |
} | |
void draw(){ | |
fill(0); | |
rect(0, 0, width, height); | |
fill(255); | |
for(int i = 0; i<snowflakes.length; i++){ | |
snowflakes[i].fall(); | |
snowflakes[i].updateGravity(); | |
snowflakes[i].show(); | |
} | |
//saveFrame("line-######.png"); | |
} | |
class snowflake{ | |
float x, y; | |
float d; | |
float gravity; | |
float maximumV; | |
snowflake(float x, float y, float d){ | |
this.x = x; | |
this.y = y; | |
this.d = d; | |
this.gravity = this.d / 3; | |
this.maximumV = this.d * 1.1; | |
} | |
void show(){ | |
if(this.y >= height+20){ | |
this.gravity = this.d/3; | |
this.y = -20; | |
} | |
if(this.x > width){ | |
this.x = 0; | |
} | |
if(this.x < 0){ | |
this.x = width; | |
} | |
ellipse(this.x,this.y,this.d,this.d); | |
} | |
void updateGravity(){ | |
if(!(this.gravity >= this.maximumV)){ | |
this.gravity+=0.05; | |
} | |
this.x += wind; | |
} | |
void fall(){ | |
this.y += this.gravity; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment