Snowflake[] snowflakes = new Snowflake[2000]; int lastFlakeIndex = -1; void setup() { size(640, 480); for (int i = 0; i <= 100; i++) { spawnNewFlake(); snowflakes[i].setY(random(height / 4)); } } void draw() { background(0); drawChristmasTree(); for (Snowflake flake : snowflakes) { if (flake == null) continue; flake.update(); flake.draw(); } spawnNewFlake(); } boolean canFallTo(int x, int y, float offset) { if (y >= height - offset) return false; color pixel = get(x, y); return pixel != #640909 && pixel != #FFFF00 && pixel != #1B7110 && pixel != #FF0000 && pixel != #990000; } void drawChristmasTree() { noStroke(); fill(#640909); rect(width / 2 - 10, height - 25, 20, 25); drawBranches(width / 2 - 100, height - 25, width / 2 + 100, height - 25, width / 2, height - 75, 3); drawBranches(width / 2 - 80, height - 50, width / 2 + 80, height - 50, width / 2, height - 100, 3); drawBranches(width / 2 - 60, height - 75, width / 2 + 60, height - 75, width / 2, height - 125, 2); drawBranches(width / 2 - 40, height - 100, width / 2 + 40, height - 100, width / 2, height - 150, 2); drawBranches(width / 2 - 30, height - 125, width / 2 + 30, height - 125, width / 2, height - 160, 2); fill(#FFFF00); drawStar(width / 2, height - 160, 20, 10, 6); } void drawBranches(int x1, int y1, int x2, int y2, int x3, int y3, int mod) { fill(#1B7110); triangle(x1, y1, x2, y2, x3, y3); for (int i = x1 + 10; i <= x2 - 10; i += 10) { fill(#FF0000); if ((i/10) % mod == 0) { fill(#990000); } circle(i, y1, 7); } } void drawStar(float x, float y, float radius1, float radius2, int nPoints) { float angle = TWO_PI / nPoints; float halfAngle = angle / 2.0; beginShape(); for (float a = 0; a < TWO_PI; a += angle) { float sx = x + cos(a) * radius2; float sy = y + sin(a) * radius2; vertex(sx, sy); sx = x + cos(a + halfAngle) * radius1; sy = y + sin(a + halfAngle) * radius1; vertex(sx, sy); } endShape(CLOSE); } void spawnNewFlake() { lastFlakeIndex++; if (lastFlakeIndex >= snowflakes.length) { lastFlakeIndex = 0; } int rg = 255 - int(random(96)); snowflakes[lastFlakeIndex] = new Snowflake(random(width), 0, 0.5 + random(1), 2 + random(3), color(rg, rg, 255)); }