效果图
代码与注释
main.pde
Particle[] p = new Particle[800];
int diagonal;
void setup() {
size(640, 480);
for (int i = 0; i<p.length; i++) {
p[i] = new Particle();
p[i].o = random(1, random(1, width/p[i].n));
}
diagonal = (int)sqrt(width*width + height * height)/2; ///< 对角线长度的一半
background(0);
noStroke();
fill(255);
frameRate(30);
}
float rotation = 0;
void draw() {
/// @note 当点击鼠标,则禁用背景清屏
if (!mousePressed) {
background(0);
}
translate(width/2, height/2);
rotation -=0.002;
rotate(rotation); ///< 外层旋转(整体粒子)
for (int i = 0; i<p.length; i++) {
p[i].draw();
/// @note 如果粒子跑出屏幕范围,则重置该粒子
if (p[i].drawDist()>diagonal) {
p[i] = new Particle();
}
}
}
复制代码
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END