xxxxxxxxxx
44
function setup() {
createCanvas(900, 900);
background(0);
dens = 10;
cols = ["#eedeab","#ffc857","#ff9f56","#e9724c","#e95339","#c5283d","#9d1f2e","#381225","#512aa3","#4077c9"]
center = createVector(random(width), random(height));
points = [];
time = 0;
for(x = 0; x < width / dens; x++){
for(y = 0; y < height / dens; y++){
points[points.length] = new Point(x * dens + random(-dens, dens), y * dens + random(-dens, dens));
}
}
blendMode(ADD);
}
function draw() {
for(i = 0; i < points.length; i++){
points[i].update();
}
time = time + 0.01;
}
class Point{
constructor(x, y){
this.pos = createVector(x, y);
this.vel = createVector(1, 0);
this.noise = 0;
this.tan = p5.Vector.sub(center, this.pos);
this.c = floor(random(cols.length));
this.col = color(cols[this.c]);
this.col.setAlpha(2)
}
update(){
this.tan = p5.Vector.sub(this.pos, center);
this.tan.setHeading(this.tan.heading() + this.c)
this.noise = map(noise(this.pos.x / 500, this.pos.y / 500, this.c / 10 + time), 0, 1, -1, 1);
this.vel.setHeading(this.noise * TWO_PI + (tan(this.tan.heading()))) ;
this.pos.add(this.vel);
stroke(this.col);
point(this.pos.x, this.pos.y)
}
}