xxxxxxxxxx
function setup() {
createCanvas(600, 600);
colorMode(HSB, 360, 100, 100);
}
function draw() {
background([0, 0, 10]);
noFill();
const r = 96;
let y = 0;
let x = 0;
scale(0.33);
// xinc is 3 size of the hexagon
const xinc = 3 * r;
// use pythagorean theorem to get our
// yinc, (sqrt((3r)^2 - (3r/2)^2)
let yinc = sqrt(0.25 * 27 * pow(r, 2));
const maxx = int((width / r) * xinc);
const maxy = int((height / r) * yinc);
for (let x = 0; x < maxx; x += xinc) {
for (let y = 0; y < maxy; y += yinc) {
const c = color(map(x, 0, maxx, 130, 180), map(y, 0, maxy, 50, 100), 95, 1);
stroke(c);
// need to shift the x spot each time we increment y
const xoff = (1.5 * r * (y / yinc));
const xx = x - xoff;
// change based on distance from center
const d = map(sin(dist(width / 2, height / 2, x, y) - radians(frameCount)), -1, 1, 0, 1);
hexx(xx, y, r, 0, {
l: false,
sw: 4,
});
hexx(xx, y, r, radians(-120), {
c: true,
sw: 2,
fc: c
});
fill([hue(c),saturation(c),80,0.2]);
noStroke();
hexx(xx, y, r, radians(-240), {
s: 1 * map(d, 0, 1, 0.25, 0.9),
r: TAU / 6 * d,
sw: 1
});
noFill();
}
}
}
function hexx(x, y, r, rot, style) {
const l = style && style.l || false;
const c = style && style.c || false;
const s = style && style.s || 1;
const rr = style && style.r || 0;
const sw = style && style.sw || 2;
push();
strokeWeight(sw);
// move to point and rotate for hexagon
translate(x, y);
rotate(rot);
// move to center before drawing
translate(-r, 0);
// style
scale(s);
rotate(rr);
if (c) {
if (style && style.fc) {
fill(style.fc);
}
circle(0, 0, r / 2);
noFill();
}
// draw hexagon now that we are in the right spot
beginShape();
for (let i = 0; i < TAU; i += TAU / 6) {
vertex(r * cos(i), r * sin(i));
if (l)
line(0, 0, r * cos(i), r * sin(i));
}
endShape(CLOSE);
pop();
}