var bgColor;
var circleColor;
var triangleColor;
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB, 360, 100, 100);
frameRate(30);
noStroke();
mousePressed();
}
function mousePressed() {
bgColor = color(random(360), 100, 100);
circleColor = color(random(360), 100, 100);
triangleColor = color(random(360), 100, 100);
}
function draw() {
blendMode(BLEND);
background(bgColor);
blendMode(EXCLUSION);
var r = 70;
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;
fill(circleColor);
ellipse(w, h, r * 2, r * 2);
fill(triangleColor);
beginShape();
for (var i = 0; i < 3; i++) {
var angle = TWO_PI / 3 * i + frameCount * 0.02;
angle += (x + y) % 2 == 0? -HALF_PI: HALF_PI;
vertex(w + r * cos(angle), h + r * sin(angle));
}
endShape(CLOSE);
}
}
}