createCanvas(210 * SCL, 297 * SCL);
describe("two hashed hexagon layer");
randomSeed(~~random(hour() + minute() + second()));
noiseSeed(random(1234567));
let S = min(width, height);
svgStr += `<g fill="none" stroke="silver" stroke-width="1">\n`;
svgStr += `<g fill="none" stroke="gold" stroke-width="1">\n`;
function drawLayer(sze) {
const dy = sze / 2 * sqrt(3);
for (let y = 0, j = 0; y < height + dy; y += dy, j++) {
for (let x = (j%2 === 0 ? 0 : dx/2); x < width + dx; x += dx) {
drawHexagon(x, y, sze+sze);
function drawHexagon(cx, cy, sze) {
const boundaryPoints = [];
for (let i = 0; i < num; i++) {
const x = cx + cos(a) * rad;
const y = cy + sin(a) * rad;
boundaryPoints.push({x: constrain(x, 0, width), y: constrain(y, 0, height)});
const a = noise(cx/321, cy/321, frameCount/123) * TAU;
for (let l = 0; l <= sze/2; l += stp) {
const p1 = {x: cx + x, y: cy + y};
clipLine(p1, {x: cx + x + v, y: cy + y - u}, boundaryPoints);
clipLine(p1, {x: cx + x - v, y: cy + y + u}, boundaryPoints);
const p1 = {x: cx - x, y: cy - y};
clipLine(p1, {x: cx - x + v, y: cy - y - u}, boundaryPoints);
clipLine(p1, {x: cx - x - v, y: cy - y + u}, boundaryPoints);
function mouseClicked() {
if (mouseButton != RIGHT && mouseX > width * 0.1 && mouseX < width * 0.9) setup();
saveSvg("epi_hashed_hexas.svg.txt");
function saveSvg(file_name) {
let svgAll = `<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">\n`;
save(svgAll.split("\n"), file_name);