是否可以更改粒子颜色?

Is it possible to change particle color?

是否可以将粒子颜色更改为心目中的任何颜色? 因为我只有一种颜色,我想更改它以使其更适合 spring 有没有一种方法可以根据您的口味配置颜色以下是我的功能代码:

function Particle() {
  this.pos = createVector(random(width), random(height));
  this.vel = createVector(0, 0);
  this.acc = createVector(0, 0);
  this.maxspeed = 4;
  this.h = 100;

  this.prevPos = this.pos.copy();

  this.update = function() {
    this.vel.add(this.acc);
    this.vel.limit(this.maxspeed);
    this.pos.add(this.vel);
    this.acc.mult(0);
  }

  this.follow = function(vectors) {
    var x = floor(this.pos.x / scl);
    var y = floor(this.pos.y / scl);
    var index = x + y * cols;
    var force = vectors[index];
    this.applyForce(force);
  }

  this.applyForce = function(force) {
    this.acc.add(force);
  }

  this.show = function() {
    strokeWeight(6);
    stroke(255, this.h, 10);
    this.h = this.h + 1;
    if (this.h > 255) {
      this.h = 100;
    }
    strokeWeight(8);
    line(this.pos.x, this.pos.y, this.prevPos.x, this.prevPos.y);
    this.updatePrev();
  }

  this.updatePrev = function() {
    this.prevPos.x = this.pos.x;
    this.prevPos.y = this.pos.y;
  }

  this.edges = function() {
    if (this.pos.x > width) {
      this.pos.x = 0;
      this.updatePrev();
    }
    if (this.pos.x < 0) {
      this.pos.x = width;
      this.updatePrev();
    }
    if (this.pos.y > height) {
      this.pos.y = 0;
      this.updatePrev();
    }
    if (this.pos.y < 0) {
      this.pos.y = height;
      this.updatePrev();
    }
  }
}

show 函数中对 stroke(255, this.h, 10) 的调用决定了 Particle class 在这种情况下绘制的线条的颜色。看起来它正在从红色循环到黄色。笔画函数为well documented. You can certainly use it to make the line drawn in this example any color you want. You can learn more about color in p5js on p5js.org.