xxxxxxxxxx
36
let hexRadius = 50;
let numRows = 25;
let numCols = 10;
function setup() {
createCanvas(800, 1200);
stroke(0);
noFill();
angleMode(DEGREES);
let yOffset = hexRadius * sqrt(0.8);
let xOffset = hexRadius * 3.1;
for (let row = 0; row < numRows; row++) {
for (let col = 0; col < numCols; col++) {
let x = col * xOffset + (row % 2) * xOffset / 2 ;
let y = row * yOffset;
drawHex(x, y);
}
}
}
function drawHex(x, y) {
let angle = 360 / 6;
for (let i = 0; i < 6; i++) {
let x0 = x + hexRadius * cos(i * angle);
let y0 = y + hexRadius * sin(i * angle);
let x1 = x + hexRadius * cos((i + 1) * angle);
let y1 = y + hexRadius * sin((i + 1) * angle);
line(x0, y0, x1, y1);
}
}