5237浏览
查看: 5237|回复: 0

[项目] Processing系列 雨

[复制链接]

代码如下:
使用了Processing自带的粒子系统,系统配置较低的电脑如果卡就调低一下粒子总数

  1. ArrayList<Particle> particles;
  2. void setup() {
  3.   size(300, 300);
  4.   ellipseMode(RADIUS);
  5.   noFill();
  6.   particles = new ArrayList<Particle>();
  7. }
  8. void draw() {
  9.   background(0);
  10.   if (particles.size() < 200) particles.add(new Particle());
  11.   for (Particle p : particles) {
  12.     p.update();
  13.     p.display();
  14.   }
  15. }
  16. class Particle {
  17.   float x, y, vy, ty, r, tr, w;
  18.   Particle() {
  19.     reset();
  20.   }
  21.   void reset() {
  22.     x = random(width);
  23.     y = random(-150, 0);
  24.     vy = random(2, 4);
  25.     ty = y + height;
  26.     r = 0;
  27.     tr = 50;
  28.     w = random(.1, 2);
  29.   }
  30.   void update() {
  31.     if (y < ty) {
  32.       y += vy;
  33.     } else {
  34.       r++;
  35.     }
  36.     if (r > tr) reset();
  37.   }
  38.   void display() {
  39.     strokeWeight(w);
  40.     if (y < ty) {
  41.       stroke(255);
  42.       point(x, y);
  43.     } else {
  44.       stroke(255, map(r, 0, tr, 255, 0));
  45.       ellipse(x, y, r, r*.5);
  46.     }
  47.   }
  48. }
复制代码
授权转载自 任远媒体实验室
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail