Skip to content

Parametric pegboard ​

Parametric pegboard, rendered in the brepjs playground
Basics · 27 lines▶ Run it in the playground

A cols × rows grid of pegs cut from a plate.

Code ​

This is the full program. The playground runs it in your browser without a change.

ts
import { box, cutAll, cylinder, unwrap } from 'brepjs/quick';

// Parametric pegboard: any width × height, fixed 25 mm grid, 6 mm pegs.
function pegboard(cols: number, rows: number) {
  const pitch = 25;
  const padding = 12.5;
  const thickness = 6;
  const pegRadius = 3;

  const W = cols * pitch + padding * 2;
  const H = rows * pitch + padding * 2;

  const plate = box(W, H, thickness, { at: [0, 0, thickness / 2] });

  const pegs = [];
  for (let i = 0; i < cols; i++) {
    for (let j = 0; j < rows; j++) {
      const x = -W / 2 + padding + i * pitch + pitch / 2;
      const y = -H / 2 + padding + j * pitch + pitch / 2;
      pegs.push(cylinder(pegRadius, thickness + 2, { at: [x, y, -1] }));
    }
  }

  return unwrap(cutAll(plate, pegs));
}

export default pegboard(6, 4);

Functions used ​

box cutAll cylinder unwrap

▶ Run Parametric pegboard in the playground

Released under the Apache 2.0 License.