xxxxxxxxxx
let dots = [];
const noiseScale = 0.2;
function setup() {
const w = windowWidth;
const h = windowHeight;
const c = createCanvas(w, h);
frameRate(30);
colorMode(HSB, 360, 100, 100);
for (let i = 0; i < 50; i++) {
const x = random(0, width) / width;
const y = random(0, height) / height;
dots.push({
x: x,
y: y,
x0: x,
y0: y,
});
}
}
function getXY(d) {
return {
x: d.x * width,
y: d.y * height,
};
}
function draw() {
const t = frameCount;
const xc = width * 0.5;
const yc = height * 0.5;
background(60, 10, 85);
strokeWeight(0.5);
fill(60, 10, 20, 1);
stroke(60, 10, 20, 0.03);
fill(60, 10, 80, 1);
stroke(60, 10, 50, 0.05);
for (let i = 0; i < dots.length; i++) {
const d = dots[i];
const {
x,
y
} = getXY(d);
const di = dist(x, y, xc, yc);
circle(x, y, 1);
for (var j = 0; j < dots.length; j++) {
if (j != i) {
const dd = dots[j];
const {
x: xd,
y: yd
} = getXY(dd);
line(x, y, xd, yd);
}
}
}
for (let i = 0; i < dots.length; i++) {
const d = dots[i];
const {
x,
y
} = getXY(d);
const {
x: x0,
y: y0
} = getXY({
x: d.x0,
y: d.y0
});
const d0 = dist(x0, y0, xc, yc);
let di = dist(x, y, xc, yc);
if (di < TAU) di = TAU;
const r = constrain(d0 / di, PI, 4*PI);
const m = noise(x * noiseScale,
y * noiseScale,
t * noiseScale) * r;
const nv = createVector(x - xc, y - yc);
nv.setMag(nv.mag() + m * cos(t / (d0 / di)));
nv.add(xc, yc);
dots[i] = {
x0: d.x0 / width,
y0: d.y0 / height,
x: nv.x / width,
y: nv.y / height,
};
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}