xxxxxxxxxx
82
function Particle() {
this.pos = createVector(random(width), random(height));
this.vel = createVector(0, 0);
this.acc = createVector(0, 0);
this.maxspeed = random(3.5) + 0.5;
this.white = floor(random(3));
// this.white = 0;
this.colours = [colours];
// this.cap = floor(random(2));
this.cap = 0;
this.currentColour = floor(random(colours.length));
this.colourHex = this.colours[this.currentColour];
this.colourSwapFrame = floor(random(1000)) + 100;
this.prevPos = this.pos.copy();
this.newColour = function () {
if (frameCount % this.colourSwapFrame === 0) {
this.currentColour++;
this.colourHex = this.colours[
(this.currentColour + 1) % this.colours.length
];
}
};
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) {
let x = floor(this.pos.x / scl);
let y = floor(this.pos.y / scl);
let index = x + y * cols;
this.applyForce(vectors[index]);
};
this.applyForce = function (force) {
this.acc.add(force);
};
this.show = function () {
// stroke(255,10);
strokeWeight(5 / this.maxspeed);
// this.cap ? strokeCap(PROJECT) : strokeCap(ROUND);
// point(this.pos.x, this.pos.y);
// fill(colourHex);
let lineColour = color(this.colourHex);
lineColour.setAlpha(10)
this.white ? stroke(lineColour): stroke(255, 10);
// circle(this.pos.x, this.pos.y, 4/this.maxspeed );
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();
}
};
}