Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ArrayList<FlakeClass> Flakeslist = new ArrayList<FlakeClass>();
- ArrayList<GustClass> gustslist = new ArrayList<GustClass>();
- ArrayList<LineClass> lineslist = new ArrayList<LineClass>();
- color b1, b2, c1, c2;
- PGraphics pg;
- float lightY = 170;
- boolean lightYDir;
- float lightYSpeed = .25;
- float movingForwardSpeed = .2;
- void setup() {
- size(800, 600);
- //fullScreen();
- Flakeslist = new ArrayList();
- gustslist = new ArrayList();
- lineslist = new ArrayList();
- newgust();
- newFlake(2000);
- pg = createGraphics(width, 260);
- c1 = color( 0);
- c2 = color(180);
- setGradient(0, 0, width, 180, c1, c2);
- noStroke();
- newline();
- }
- void newline() {
- lineslist.add(new LineClass(height - 160));
- lineslist.add(new LineClass(height - 60));
- //lineslist.add(new LineClass(height - 158));
- //lineslist.add(new LineClass(height - 92));
- //lineslist.add(new LineClass(height - 26));
- }
- void newgust() {
- for (int i = 0; i < 4; i ++) {
- float gH = random (height);
- gustslist.add(new GustClass());
- }
- }
- void newFlake( int flakeNum) {
- for (int i = 0; i < flakeNum; i ++) {
- float s = random(2, 4);
- Flakeslist.add(new FlakeClass(random(width), random(-120, height - 120), s));
- }
- }
- void mouseReleased() {
- newFlake(20);
- }
- void draw() {
- background(1);
- if (lightYDir) { // gives the light a little moevement on the ground
- lightY += lightYSpeed;
- } else {
- lightY -= lightYSpeed;
- }
- if ( lightY >=176) {// lightY <= 156){
- lightYDir = !lightYDir;
- lightY = 176;
- lightYSpeed = random(.1, .3);
- }
- if ( lightY <= 156) {// lightY <= 156){
- lightYDir = !lightYDir;
- lightY = 156;
- lightYSpeed = random(.1, .3);
- }
- image(pg, 0, height - lightY); // put the light on the ground
- for (int i = Flakeslist.size()-1; i >= 0; i--) {
- FlakeClass dFlake = Flakeslist.get(i);
- dFlake.display(); // show every flake
- dFlake.fall(); // move every flake
- }
- for (int i = gustslist.size()-1; i >= 0; i--) {
- GustClass dgust = gustslist.get(i);
- // dgust.display(); //uncomment to "see" the gusts of wind
- dgust.moveGust(); // move the gusts of wind.
- }
- for (int i = lineslist.size()-1; i >= 0; i--) {
- LineClass dline = lineslist.get(i);
- dline.display();
- }
- }
- // make the light gradient PGraphic. This way we only create the gradient once.
- //Less work for computer means more snowflakes!
- void setGradient(int x, int y, float w, float h, color c1, color c2) {
- pg.beginDraw();
- pg.noFill();
- for (int i = 0; i <= height; i++) {
- float inter = map(i, y, y+h, 0, 1);
- color c = lerpColor(c2, c1, inter);
- pg.stroke(c);
- pg.strokeWeight(3);
- pg.ellipse(width/2, 200, i*4, i*2.3);
- }
- pg.endDraw();
- }
- // Snowflake class
- class FlakeClass {
- float x, y, fallSpeed; // declare the variables used in the class
- float flakeSize, originalflakeSize, originalflakeX;
- float gustInfluence = random(.1, 3); // how much the wind affects the snowflake
- int alph = 255;
- boolean falling = true;
- int hitHeight;
- FlakeClass(float _x, float _y, float _flakeSize) {
- x = _x;
- y = _y;
- flakeSize = _flakeSize;
- originalflakeSize = _flakeSize;
- originalflakeX = x;
- fallSpeed = map(flakeSize, 2, 6, .5, 2);
- hitHeight = int(map(fallSpeed, .5, 2, height-10, height - 240));
- }
- void fall() {
- y += fallSpeed;
- if (y > hitHeight) {
- falling = false;
- }
- float wboost = map(x, 0, width, -1, 1); // move away from center while falling.
- if (falling == false) {
- alph -= 3;
- fallSpeed = movingForwardSpeed; // moves the flakes forward constant speed after they land.
- wboost = map(x, 0, width, -.25, .25); // move away from center while on ground.
- }
- if (alph <= 0 ) { //reset back to top
- y = -10;
- falling = true;
- flakeSize = originalflakeSize;
- x = originalflakeX;
- fallSpeed = map(flakeSize, 2, 6, .5, 2);
- alph = 255;
- }
- flakeSize += .005;
- x += wboost; // make it "zoom"
- if (falling) {
- for (int i = gustslist.size()-1; i >= 0; i--) { // look through every gust
- GustClass dgust = gustslist.get(i);
- float d = dist(dgust.x, dgust.y, x, y);
- float gboost = 0;
- if (d < dgust.gustSize) {
- gboost = map(d, 0, 200, gustInfluence, 0);
- }
- if (dgust.gustDir) {
- x -= gboost;
- } else {
- x += gboost;
- }
- }
- }
- }
- void display() {
- float snowValue = 60;
- int lightFalloff = 300;
- float dis = dist(x, y, width/2, height - 100);
- if (dis < lightFalloff) {
- snowValue = map(dis, lightFalloff, 0, 60, 255);
- }
- float moveLight = map(lightY, 156, 176, -20, 20);
- snowValue += moveLight;
- // if( lightY >=176 || lightY <= 156){
- fill(snowValue, alph);
- if (falling) {
- ellipse(x, y, flakeSize, flakeSize);
- } else {
- float perspectiveFlake = map(y, height - 100, height, .7, 1.2);
- ellipse(x, y, (flakeSize * perspectiveFlake) * 1.2, (flakeSize * perspectiveFlake)/1.2);
- }
- }
- }
- // wind class
- class GustClass {
- float x, y, speed; // declare the variables used in the class
- int counter = 200;
- int gustSize;
- boolean gustDir;
- GustClass() {
- //gustDir = _dir;
- resetGust();
- }
- void resetGust() {
- y = random(height);
- gustDir = false;
- if (random(2) > 1) {
- gustDir = true;
- }
- if (!gustDir) {
- x = random(-100, -20);
- }
- else{
- x = random(width + 20, width + 100);
- }
- speed = random(.5, 3.25);
- gustSize = int(random(100, 300));
- }
- void moveGust() {
- if (gustDir) {
- x -= speed;
- } else {
- x += speed;
- }
- if (x > width + 120 || x < -120 ) {
- resetGust();
- }
- }
- void display() {
- stroke(0, 0, 255);
- noFill();
- ellipse(x, y, gustSize, gustSize);
- }
- }
- /// line class
- class LineClass {
- float x, y; // declare the variables used in the class
- int counter = 200;
- float speed = movingForwardSpeed;
- LineClass( float _y) {
- y = _y; // height - 160
- }
- boolean finished() {
- counter --;
- if ( counter <= 0 ) {
- return true;
- } else {
- return false;
- }
- }
- void display() {
- float displaceX = map(y, height - 160, height, 30, 186);
- x = width/2 - 83 - displaceX;
- y += speed;
- float lineValue = 60;
- int lightFalloff = 300;
- float dis = dist(x, y, width/2 - 60, height - 160);
- if (dis < lightFalloff) {
- lineValue = map(dis, lightFalloff, 0, 180, 0);
- }
- if (y > height + 40) {
- y = height - 160;
- speed = movingForwardSpeed;
- }
- float moveLight = map(lightY, 156, 176, -20, 20);
- fill(lineValue, 180);
- pushMatrix();
- translate(x, y);
- float displaceScale = map(y, height - 160, height, 2, 10);
- scale(displaceScale);
- beginShape();
- vertex(1, -2);
- vertex(3, -2);
- vertex(-1, 2);
- vertex(-4, 2);
- endShape(CLOSE);
- popMatrix();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement