birds.pde
来自「This is processing for java examples.」· PDE 代码 · 共 54 行
PDE
54 行
/** * 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 arrayint 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(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?