xxxxxxxxxx
98
let N = 6;
let div = 6;
let radius = 100;
let rMax = 120;
let completionPercentage = 0;
let rate = 0.00007;
function setup() {
//w = min(windowWidth, windowHeight);
//createCanvas(w, w);
createCanvas(windowWidth, windowHeight);
strokeWeight(4);
stroke("orange");
completionPercentages = [];
for (n = 0; n < N; n++) {
rateOffset = map(n, 0, N, 0, 1);
completionPercentages.push(rateOffset);
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
shift = 0
function draw() {
background(0);
translate(windowWidth / 2, windowHeight / 2);
for (n = 0; n < N; n++) {
if(n%2==0){
shift = PI/2
}else{
shift = 0
}
for (a = shift; a < TAU+shift; a += TAU / div) {
completionPercentages[n] += rate;
if (completionPercentages[n] > 1) {
completionPercentages[n] = 0;
}
radius = map(completionPercentages[n], 0, 1, 0, rMax);
x = radius * cos(a);
y = radius * sin(a);
maxStrokeWeight = 1.4;
maxStrokeLength = 10;
d = dist(x, y, 0, 0);
dWeight = map(d, 0, rMax, 1, 0);
strokeWeight(dWeight*maxStrokeWeight);
strokeLength = dWeight*maxStrokeLength;
minDist = 20;
if (d < minDist) {
dWeight = map(d, 0, minDist, 0, 1);
strokeWeight(dWeight*maxStrokeWeight);
strokeLength = dWeight*maxStrokeLength;
}
point(x, y);
vRight = createVector(
radius * cos(a + TAU / div),
radius * sin(a + TAU / div)
);
angleRight = atan2(vRight.x - x, vRight.y - y);
vecRight = createVector(
x + strokeLength * sin(angleRight),
y + strokeLength * cos(angleRight)
);
line(x, y, vecRight.x, vecRight.y);
vLeft = createVector(
radius * cos(a - TAU / div),
radius * sin(a - TAU / div)
);
angleLeft = atan2(vLeft.x - x, vLeft.y - y);
vecLeft = createVector(
x + strokeLength * sin(angleLeft),
y + strokeLength * cos(angleLeft)
);
line(x, y, vecLeft.x, vecLeft.y);
}
}
}