xxxxxxxxxx
71
function setup() {
createCanvas(900, 900);
center = createVector(width / 2, height / 2);
layers = floor(random(20) + 3);
count = floor(random(10) + 3);
dots = [];
cols = ["#001219","#005f73","#0a9396","#94d2bd","#e9d8a6","#ee9b00","#ca6702","#bb3e03","#ae2012","#9b2226"];
spoke = createVector(1, 0);
layerSize = width / 2 / layers;
spoke.setMag(layerSize);
angle = TWO_PI / count;
spoke.setHeading(-HALF_PI);
pos = p5.Vector.add(center, spoke);
for(i = 0; i < layers; i++){
for(j = 0; j < count; j++){
spoke.setHeading(spoke.heading() + angle);
pos = p5.Vector.add(center, spoke);
dots[dots.length] = new Dot(pos.x, pos.y, dots.length, i, j);
}
count = floor(random(10) + 3);
angle = TWO_PI / count;
spoke.setMag(spoke.mag() + layerSize)
}
}
function draw() {
background(255);
for(i = 0; i < dots.length; i++){
dots[i].update();
}
}
class Dot{
constructor(x, y, index, layer, j){
this.pos = createVector(x, y);
this.index = index;
this.sp = p5.Vector.sub(this.pos, center);
this.layer = layer;
this.count = count;
this.col = color(cols[this.layer % cols.length]);
}
update(){
// circle(this.pos.x, this.pos.y, 10);
this.sp.setHeading(this.sp.heading() + 0.01);
// this.sp.setMag(this.sp.mag() + sin((this.sp.heading() * 4) * 0.01 ) * 20)
this.pos = p5.Vector.add(this.sp, center);
if(this.index < dots.length-1){
fill(this.col);
stroke(this.col);
circle(this.pos.x, this.pos.y, this.sp.mag() * 0.1);
if(this.layer == dots[this.index + 1].layer){
line(this.pos.x, this.pos.y, dots[this.index + 1].pos.x, dots[this.index + 1].pos.y);
}
if(this.layer !== dots[this.index + 1].layer){
line(this.pos.x, this.pos.y, dots[this.index - this.count + 1].pos.x, dots[this.index - this.count + 1].pos.y);
}
}
if(this.index == dots.length-1){
circle(this.pos.x, this.pos.y, this.sp.mag() * 0.1);
line(this.pos.x, this.pos.y, dots[this.index - this.count + 1].pos.x, dots[this.index - this.count + 1].pos.y);
}
}
}