xxxxxxxxxx
int numFlakes = 8192;
float flakeSpeed = 2;
float minSpeed = 0.5;
float flakeRange = 1;
Flake[] flakes = new Flake[numFlakes];
void setup() {
size(640, 480);
smooth();
noStroke();
for (int i = 0; i < numFlakes; i++) {
flakes[i] = new Flake(new PVector(random(width), random(height)), new PVector(random(-flakeRange, flakeRange), random(1, flakeRange*2)), random(8));
}
}
void draw() {
background(13, 26, 129);
for (int i = 0; i < numFlakes; i++) {
flakes[i].run();
flakes[i].display();
}
fill(255, 0, 0);
ellipse(-8, height/2+(8*sin(frameCount/3.0)), 32, 32);
}
class Flake {
float flakeSize;
PVector position, direction;
Flake(PVector position_, PVector direction_, float flakeSize_) {
position = position_;
direction = direction_;
flakeSize = flakeSize_;
}
void run() {
position.add(direction);
if (position.y > height) {
position = new PVector(random(width), 0);
direction = new PVector(random(-flakeRange, flakeRange), random(1, flakeRange*2));
flakeSize = random(8);
}
}
void display() {
float offset = 8*sin(frameCount/3.0);
fill(0, 64);
if ((position.y < position.x/3 + height/2 + offset) && (position.y > -position.x/3 + height/2 + offset ) ) {
fill(255, 0, 0);
}
ellipse(position.x, position.y, flakeSize, flakeSize);
}
}