mirror of
https://github.com/processing/processing4.git
synced 2026-02-02 21:29:17 +01:00
54 lines
1.3 KiB
Plaintext
Executable File
54 lines
1.3 KiB
Plaintext
Executable File
/**
|
|
* Crazy Flocking 3D Birds
|
|
* by Ira Greenberg.
|
|
*
|
|
* Simulates a flock of birds using a Bird class and nested
|
|
* pushMatrix() / popMatrix() functions.
|
|
* Trigonometry functions handle the flapping and sinuous movement.
|
|
*/
|
|
|
|
// Flock array
|
|
int birdCount = 200;
|
|
Bird[]birds = new Bird[birdCount];
|
|
float[]x = new float[birdCount];
|
|
float[]y = new float[birdCount];
|
|
float[]z = new float[birdCount];
|
|
float[]rx = new float[birdCount];
|
|
float[]ry = new float[birdCount];
|
|
float[]rz = new float[birdCount];
|
|
float[]spd = new float[birdCount];
|
|
float[]rot = new float[birdCount];
|
|
|
|
void setup() {
|
|
size(640, 360, P3D);
|
|
noStroke();
|
|
|
|
// Initialize arrays with random values
|
|
for (int i = 0; i < birdCount; i++){
|
|
birds[i] = new Bird(random(-300, 300), random(-300, 300),
|
|
random(-500, -2500), random(5, 30), random(5, 30));
|
|
|
|
x[i] = random(20, 340);
|
|
y[i] = random(30, 350);
|
|
z[i] = random(1000, 4800);
|
|
rx[i] = random(-160, 160);
|
|
ry[i] = random(-55, 55);
|
|
rz[i] = random(-20, 20);
|
|
spd[i] = random(.1, 3.75);
|
|
rot[i] = random(.025, .15);
|
|
}
|
|
}
|
|
|
|
void draw() {
|
|
background(0);
|
|
lights();
|
|
for (int i = 0; i < birdCount; i++){
|
|
birds[i].setFlight(x[i], y[i], z[i], rx[i], ry[i], rz[i]);
|
|
birds[i].setWingSpeed(spd[i]);
|
|
birds[i].setRotSpeed(rot[i]);
|
|
birds[i].fly();
|
|
}
|
|
}
|
|
|
|
|