  
代码如下: 
使用了Processing自带的粒子系统,系统配置较低的电脑如果卡就调低一下粒子总数 
 
			
			
			- ArrayList<Particle> particles;
 -  
 - void setup() {
 -   size(300, 300);
 -   ellipseMode(RADIUS);
 -   noFill();
 -   particles = new ArrayList<Particle>();
 - }
 -  
 - void draw() {
 -   background(0);
 -   if (particles.size() < 200) particles.add(new Particle());
 -   for (Particle p : particles) {
 -     p.update();
 -     p.display();
 -   }
 - }
 -  
 - class Particle {
 -   float x, y, vy, ty, r, tr, w;
 -   Particle() {
 -     reset();
 -   }
 -   void reset() {
 -     x = random(width);
 -     y = random(-150, 0);
 -     vy = random(2, 4);
 -     ty = y + height;
 -     r = 0;
 -     tr = 50;
 -     w = random(.1, 2);
 -   }
 -   void update() {
 -     if (y < ty) {
 -       y += vy;
 -     } else {
 -       r++;
 -     }
 -     if (r > tr) reset();
 -   }
 -   void display() {
 -     strokeWeight(w);
 -     if (y < ty) {
 -       stroke(255);
 -       point(x, y);
 -     } else {
 -       stroke(255, map(r, 0, tr, 255, 0));
 -       ellipse(x, y, r, r*.5);
 -     }
 -   }
 - }
 
  复制代码 授权转载自 任远媒体实验室 
 |