xxxxxxxxxx
135
let ddens = 100;
let fdens = 25;
let i = 0;
let a = 0;
function setup() {
createCanvas(900, 900);
center = createVector(width / 2, height / 2);
forces = [];
dots = [];
cols = ["#ffc857","#ee9550","#e9724c","#d74845","#c5283d","#a41c32","#471d33","#3e2e6d","#255f85","#269480"];
for(i = 0; i < width / fdens; i++){
for(j = 0; j < height / fdens; j++){
forces[forces.length] = new Force(i * fdens + random(-fdens, fdens), j * fdens + random(-fdens, fdens), forces.length);
}
}
for(i = 0; i < width / ddens; i++){
for(j = 0; j < height / ddens; j++){
dots[dots.length] = new Dot(i * ddens, j * ddens, dots.length);
}
}
strokeWeight(0.1);
stroke(0);
background(255);
}
function draw() {
for(i = 0; i < forces.length; i++){
forces[i].update();
}
for(i = 0; i < dots.length; i++){
dots[i].update();
}
// stroke(0);
// fill(0);
// circle(center.x, center.y, width / 4);
// stroke(255);
// fill(255, 240);
// circle(center.x - width / 15, center.y - width / 15, width / 10);
// stroke(0);
}
class Dot{
constructor(x, y, index){
this.pos = createVector(x, y);
this.npos = createVector(x, y);
this.vel = createVector(1, 0);
this.fadd = createVector(1, 0);
this.vel.limit(1);
this.dist = createVector(x, y);
this.index = index;
this.dc = 1;
this.c = floor(random(cols.length));
this.col = color(cols[this.c]);
}
update(){
this.dc = 1;
for(a = 0; a < dots.length; a++){
if(a !== this.index){
this.dist = p5.Vector.sub(this.pos, dots[a].pos);
if(this.dist.mag() < 50){
this.dc = this.dc + 1;
this.dist.setMag(map(this.dist.mag(), 0, 50, 1, 0))
this.vel.add(this.dist);
}
}
}
for(a = 0; a < forces.length; a++){
// if(forces[a].fa > 0){
this.dist = p5.Vector.sub(forces[a].pos, this.pos);
// this.fadd = forces[a].vel;
if(this.dist.mag() < 200){
// forces[a].fa = forces[a].fa + 0.01
this.dist.setMag(map(this.dist.mag(), 0, 50, 0, 1) * forces[a].fa);
this.vel.add(this.dist);
}
// }
}
this.vel.limit(1);
this.npos.add(this.vel);
if(frameCount > 50){
// stroke(this.col);
// point(this.pos.x, this.pos.y);
line(this.pos.x, this.pos.y, this.npos.x, this.npos.y);
}
this.pos.add(this.vel);
if(this.pos.x < 0 || this.pos.x > width || this.pos.y < 0 || this.pos.y > height){
this.pos = createVector(random(width), random(height));
this.npos = createVector(this.pos.x, this.pos.y);
this.vel.setMag(1);
}
}
}
class Force{
constructor(x, y, index){
this.pos = createVector(x, y);
this.fa = 0;
this.vel = createVector(1, 0);
this.dist = p5.Vector.sub(this.pos, center);
this.index = index;
}
update(){
this.fa = map(noise(this.index, frameCount / 100), 0, 1, -1, 1);
// if(frameCount % 1000 == true){
// this.pos = createVector(random(width), random(height));
// }
// fill(255, 125, 0);
// circle(this.pos.x, this.pos.y, 5);
// this.dist = p5.Vector.sub(this.pos, center);
// this.vel.setHeading(this.dist.heading() + HALF_PI);
// this.pos.add(this.vel);
}
}