Created
December 20, 2020 17:31
-
-
Save sasaki-shigeo/607ac04aef2d7a39248b17e6a7edbe37 to your computer and use it in GitHub Desktop.
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
ArrayList<Star> stars = new ArrayList<Star>(); | |
ArrayList<Crystal> snow = new ArrayList<Crystal>(); | |
void setup() { | |
size(800, 600); | |
colorMode(HSB, 360, 1.0, 1.0, 1.0); | |
for (int i = 0; i < 30; i++) { | |
stars.add(new Star(random(width), random(0.7 * height), 30)); | |
} | |
for (int i = 0; i < 100; i++) { | |
snow.add(new Crystal(random(width), random(height), 15)); | |
} | |
} | |
void draw() { | |
background(#0000cc); | |
for (Star s: stars) { | |
s.show(); | |
} | |
fill(#663300); | |
triangle(0.5 * width, 0.3 * height, | |
0.45 * width, 0.9 * height, | |
0.55 * width, 0.9 * height); | |
fill(#008800); | |
triangle(0.5 * width, 0.3 * height, | |
0.3 * width, 0.75 * height, | |
0.7 * width, 0.75 * height); | |
fill(#cccccc); | |
rect(0, 0.9*height, width, 0.1 * height); | |
for (Crystal c: snow) { | |
c.show(); | |
c.fall(); | |
} | |
} | |
class Star { | |
float x; | |
float y; | |
float r; | |
float rand_id = random(1200); | |
Star(float x, float y, float sz) { | |
this.x = x; | |
this.y = y; | |
this.r = sz / 2; | |
} | |
void show() { | |
if ((rand_id + frameCount) % 1200 < 30) { | |
return; | |
} | |
push(); | |
noStroke(); | |
fill(#ffff00); | |
translate(x, y); | |
rotate(radians(-90)); | |
beginShape(); | |
for (int i = 0; i < 5; i++) { | |
vertex(r * cos(radians(144 * i)), | |
r * sin(radians(144 * i))); | |
} | |
endShape(CLOSE); | |
pop(); | |
} | |
} | |
class Crystal { | |
float x; | |
float y; | |
float r; | |
float rand_id = random(1.0); | |
Crystal(float x, float y, float sz) { | |
this.x = x; | |
this.y = y; | |
this.r = sz / 2; | |
} | |
void show() { | |
push(); | |
fill(#ffffff); | |
stroke(#ffffff); | |
strokeWeight(2); | |
float amp = -50 + 100 * noise(x / width, y / height); | |
amp = 25 * sin(2 * PI * (y / height + rand_id)); | |
translate(floor(x + amp), y); | |
for (int i = 0; i < 6; i++) { | |
line(0, 0, r * cos(radians(60 * i)), r * sin(radians(60 * i))); | |
} | |
pop(); | |
} | |
void fall() { | |
y += 0.5; | |
if (y >= height) { | |
y = 0; | |
x = random(width); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment