xxxxxxxxxx
let circles = [];
let N = 12;
function setup() {
createCanvas(800, 800);
pixelDensity(2);
background(0);
for(let i=0; i<N; i++){
let radius = random(50, 200);
let x = random(radius, width - radius);
let y = random(radius, height - radius);
circles[i] = new Circle(x, y, radius);
}
}
function draw() {
stroke(190, random(3, 5));
drawingContext.setLineDash([1, 3, 7, 5, 42]);
noFill();
for(let i=0; i<circles.length; i++){
circles[i].rotate();
line(circles[i].x, circles[i].y, circles[i].px, circles[i].py);
}
stroke(random(0, 250), random(25, 95), random(195, 255), random(2, 4));
drawingContext.setLineDash([1, 5, 5, 300, 1]);
for(let i=0; i<circles.length-1; i++){
for(let j=i+1; j<circles.length; j++){
line(circles[i].px, circles[i].py, circles[j].px, circles[j].py);
}
}
}
class Circle {
constructor(x, y, r){
this.x = x;
this.y = y;
this.r = r;
this.angle = random(TWO_PI);
this.speed = random(0.01, 0.1);
this.px = null;
this.py = null;
this.rotations = 0;
this.maxRotations = random(5, 20);
}
rotate(){
if (this.rotations < this.maxRotations) {
this.px = this.x + cos(this.angle) * this.r;
this.py = this.y + sin(this.angle) * this.r;
this.angle += this.speed;
if (this.angle >= TWO_PI) {
this.rotations++;
this.angle = 0;
}
}
}
}
function keyPressed() {
if (keyCode === 83) {
saveCanvas('n-circles__a-' + floor(random(100)), 'png');
}
}