Last active
December 12, 2016 17:16
-
-
Save sasaki-shigeo/7744423 to your computer and use it in GitHub Desktop.
Demonstration of snow falling (the number of crystals is fixed) /雪の降下アニメーション (雪の結晶の個数固定)
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
class Crystal { | |
float x, y, phi; | |
Crystal(float x0, float y0, float phi0) { | |
x = x0; | |
y = y0; | |
phi = phi0; | |
} | |
void fall() { | |
y += 1; | |
} | |
void show() { | |
noStroke(); | |
ellipse(x, y, phi, phi); | |
} | |
} | |
Crystal[] crystals = new Crystal[100]; | |
void setup() { | |
size(500, 500); | |
for (int i = 0; i < crystals.length; i++) { | |
crystals[i] = new Crystal(random(width), random(height), 20); | |
} | |
} | |
void draw() { | |
background(180); | |
for (int i = 0; i < crystals.length; i++) { | |
crystals[i].fall(); | |
crystals[i].show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment