xxxxxxxxxx
/*
author: Kevin L. Smith
colors from https://artsexperiments.withgoogle.com/artpalette/colors/dcdbd8-494844-21211e-0b0a09-898783
*/
const points = [];
const I = 5;
const J = 200;
const K = 100000 / J;
const color0 = [273, 9, 13, 100];
const color1 = [273, 42, 100, 100];
const color2 = [273, 20, 100, 100];
const ptSetup = xBar;
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(640, 640);
colorMode(HSB);
noStroke();
background(color0);
ptSetup();
}
function spiral(a, theta) {
// bounded fermat spiral
return atan(a * sqrt(theta));
}
function draw() {
if (frameCount > K) {
return;
}
let zoom = width / I;
const friction = 10;
const size = 1;
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);
}
}
}
/**************************************
interaction
**************************************/
function keyReleased() {
// press 's' to save an image
if (keyCode === 83) {
saveCanvas(c, 'png');
return false;
}
}