2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Processingで雪を降らせる

Last updated at Posted at 2019-02-18

概要

Processingで雪を降らせる方法をメモ.
奥行きを出すため、サイズと速さが連動しています(スピードが遅い雪は小さい).

コード

class Snowflake { //Snowflake Class
  float x; //x axis
  float y; //y axis
  float s; //size
  color c; //color
  float dy; //speed
        Snowflake() { //Function to create snowflakes
        x = random(width); //initial x point is random
        y = random(height);
        dy = random(0, 3); // Falling speed is random between 3 and 10
        s =  5 * dy / 4.0; //Size is small if initial speed is slow
        c = #ffffff; //white snow
        }
       void drop() { //create snow and move
        y += dy;
        if (y > height) y = 0; //if snow gets the bottom of the screen, return to top
        noStroke(); //no outline
        fill(c);
        ellipse(x, y, s, s);
    }
}
Snowflake[] sf = new Snowflake[5000]; //prepare the area for 1000 snow object




void setup(){
  size (600,600);
  noCursor();
  for (int i = 0; i < 2000; i++) { //雪⽚オブジェクトを1000 個作る
  sf[i] = new Snowflake();
  }
}

 
void draw() {
   background(12,15,32);
    for(int i = 0; i < 2000; i++) {
    sf[i].drop();
}
}

結果

processingimage

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?