xxxxxxxxxx
78
function setup() {
createCanvas(900, 900);
center = createVector(width / 2, height / 2);
dots = [];
cols = ["#011627","#fdfffc","#2ec4b6","#e71d36","#ff9f1c","#002642","#840032","#e59500","#e5dada","#02040f"];
dens = width / cols.length * 0.1;
// for(i = 0; i < width / dens; i++){
// dots[dots.length] = new Dot(i * dens + 1, height / 2, dots.length);
// }
dots[0] = new Dot(width / 4, height / 4, dots.length);
c = 0;
background(255);
strokeWeight(0.1);
// blendMode(ADD)
// noiseSeed(50);
}
function draw() {
for(t = 0; t < 1000; t++){
for(i = 0; i < dots.length; i++){
dots[i].update();
}
}
if(frameCount % 50 == true){
c = (c + 1) % cols.length;
}
}
class Dot{
constructor(x, y, index){
this.cpos = createVector(x, y);
this.npos = createVector(x, y);
this.vel = createVector(1, 0);
this.dist = p5.Vector.sub(this.cpos, center);
this.index = index;
this.c = this.index % cols.length;
this.col = color(cols[this.c]);
// this.col.setAlpha(2)
this.rev = 0;
this.pa = 0;
}
update(){
this.dist = p5.Vector.sub(this.cpos, center);
if(this.pa > 3.139 && map(this.dist.heading(), -PI, PI, 0, TWO_PI) < 1){
this.rev = this.rev + 1;
// this.moving = 1;
}
this.dist.setMag(map(noise(map(sin(this.dist.heading() + this.index / 10 + this.rev / 1000), -1, 1, 0, TWO_PI) * 0.25, this.rev / 500 + this.index / dots.length), 0, 1, 0, 1) * height * 0.6);
this.npos = p5.Vector.add(center, this.dist);
// this.vel.setHeading((this.dist.heading() + HALF_PI) + map((sin(frameCount / 20 + this.index / dots.length)), -1, 1, -1, 1));
this.npos.add(this.vel);
// if(frameCount % 5 == true){
// this.c = (this.c + 1) % cols.length;
// }
this.col = color(cols[c]);
stroke(this.col);
if(frameCount > 5 && this.moving == 0){
line(this.cpos.x, this.cpos.y, this.npos.x, this.npos.y);
}
this.moving = 0;
this.cpos = p5.Vector.add(center, this.dist);
this.dist = p5.Vector.sub(this.cpos, center);
this.vel.setHeading((this.dist.heading() + HALF_PI));
this.cpos.add(this.vel);
// point(this.cpos.x, this.cpos.y);
this.pa = map(this.dist.heading(), -PI, PI, 0, TWO_PI);
}
}