xxxxxxxxxx
let dotSize = 30;
let angle = 0;
let counter = 0;
let numDots;
let radii = [];
let thetas = [];
function setup() {
createCanvas(windowWidth, windowHeight);
background(0);
noStroke();
fill(255);
// frameRate(40);
colorMode(HSB, 360, 100, 100, 100);
numDots = width/8;
for (let r = 0; r < numDots; r++) {
radii[r] = random(dotSize*2, sqrt(sq(width/2)+sq(height/2)));
}
}
function draw() {
for (let r = 0; r < radii.length; r++) {
radii[r] = (radii[r]+1)%(width/1.7);
}
for (let a = 0; a < numDots; a++) {
thetas[a] = a;
}
background(0);
drawWhole();
counter += 0.3;
}
function drawWhole() {
push();
translate(width/2, height/2);
drawHalf();
rotate(radians(90));
drawHalf();
pop();
}
function drawHalf() {
//bottom
drawSlice();
//left
push();
scale(-1, 1);
drawSlice();
pop();
//top
push();
scale(-1, -1);
drawSlice();
pop();
//right
push();
scale(1, -1);
drawSlice();
pop();
}
function drawSlice() {
let colour;
for (let i = 0; i < numDots; i++) {
colour = (i/2+counter*3)%360;
fill(colour, 80, 100, 70);
drawDots(radii[i], thetas[i]);
}
}
function drawDots(radius_, angle_) {
ellipse(cX(radius_, angle_), cY(radius_, angle_), dotSize, dotSize);
if (angle > 45) {
angle = 0;
}
}
function cX(r_, theta_) {
return x = r_ * cos(radians(theta_));
}
function cY(r_, theta_) {
return r_ * sin(radians(theta_));
}