xxxxxxxxxx
/* author: Kevin L. Smith */
const points = [];
const size = 1;
const friction = 500;
const ptSetup = xBar;
const noiseScale = 0.03;
const revolutionScale = 3.14**2;
const I = 2;
const J = 100;
const K = 15000 / J;
const color0 = [45, 39, 16, 100];
const color1 = [3, 53, 80, 100];
const color2 = [31, 71, 90, 100];
let c;
function xBar() {
for (let i = 0; i <= I; i++) {
// top-left to bottom-right
points.push({
x0: i * width / I,
y0: i * height / I
});
// bottom-left to top-right
points.push({
x0: i * width / I,
y0: height - i * height / I
});
// across middle
points.push({
x0: i * width / I,
y0: height / 2
});
}
}
function grid() {
for (let i = 0; i <= I; i++) {
for (let j = 0; j <= I; j++) {
points.push({
x0: i * width / I,
y0: j * height / I
});
}
}
}
function setup() {
c = createCanvas(1024, 1024);
colorMode(HSB);
noStroke();
background(color0);
ptSetup();
frameRate(30);
}
function spiral(a, theta) {
// bounded fermat spiral
return atan(a * sqrt(theta));
}
function draw() {
if (frameCount > K) {
return;
}
let zoom = width / I;
for (let i = 0; i < points.length; i++) {
const point = points[i];
for (let j = 1; j <= J; j++) {
const theta = frameCount * j / friction;
const a = 0.24;
// first spiral
let r = spiral(a, theta);
let x = r * cos(theta) * zoom;
let y = r * sin(theta) * zoom;
fill(color1);
circle(point.x0 + x, point.y0 + y, size);
// second spiral
r = spiral(-a, theta);
x = r * cos(theta) * zoom;
y = r * sin(theta) * zoom;
fill(color2);
circle(point.x0 + x, point.y0 + y, size);
}
const angle = noise(point.x0 * noiseScale,
point.y0 * noiseScale) * TWO_PI * revolutionScale;
points[i] = {
x0: point.x0 + cos(angle),
y0: point.y0 + sin(angle)
};
}
}
/**************************************
interaction
**************************************/
function keyReleased() {
// press 's' to save an image
if (keyCode === 83) {
saveCanvas(c, 'png');
return false;
}
}