粒子云的创建、控制与可视化
1. 控制多个粒子
在处理多个粒子时,我们可以通过修改 Particle 类中的 move 函数来限制粒子在画布内移动。以下是修改后的 move 函数:
public void move() {
// calculate the particle's distance from the center
if (dist(this.x, this.y, 0, 0) > 250) {
// create position and new random target position
PVector position = new PVector(this.x, this.y);
PVector target = new PVector(random(-250, 250), random(-250, 250));
// calculate direction vector between
// current and target position
PVector direction = PVector.sub(target, position);
// divide direction by 600 to make the steps small
direction.div(600);
// set the new direction for the particle
超级会员免费看
订阅专栏 解锁全文
1653

被折叠的 条评论
为什么被折叠?



