var colors;
var isDarkest = true;
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(30);
noStroke();
colors = [
color(255, 255, 0),
color(255, 0, 255),
color(0, 255, 255),
];
}
function mousePressed() {
isDarkest = !isDarkest;
}
function draw() {
blendMode(BLEND);
if (isDarkest) {
background(255);
blendMode(DARKEST);
} else {
background(0);
blendMode(LIGHTEST);
}
var r = 50;
for (var x = -2; x * sqrt(3) / 2 * r <= width + r; x++) {
var w = x * sqrt(3) / 2 * r;
for (var y = -2; y * 3 / 2 * r <= height + r; y++) {
var h = y * 3 / 2 * r;
h += (x + y) % 2 == 0 ? r / 4: -r / 4;
noStroke();
for (var i = 0; i < 3; i++) {
fill(colors[i]);
var angle = TWO_PI / 3 * i + frameCount * 0.04 + (x + y) * 0.07;
angle += (x + y) % 2 == 0? -HALF_PI: HALF_PI;
ellipse(w + r * cos(angle), h + r * sin(angle), 25, 25);
}
}
}
}