Live coding video of Lego Bricks
This video shows the new methods multiply() and distribute_grid() which are used here to build a presentation of some parameterized Lego bricks.
use std::geo2d::*;
use std::ops::*;
use std::math::*;
const SPACING = 8mm;
const THICKNESS = 1.2mm;
const BASE_HEIGHT = 9.6mm;
const TOLERANCE = 0.2mm;
part LegoBrick(rows = 2, columns = 4, base_height = BASE_HEIGHT) {
width = columns * SPACING - TOLERANCE;
height = rows * SPACING - TOLERANCE;
base = {
Frame(width, height, THICKNESS);
r = rows - 1;
c = columns - 1;
n_rings = r * c;
if n_rings > 0 {
Ring(outer_d = 6.51mm, inner_d = 4.8mm)
.multiply(n_rings)
.distribute_grid(
width = width - width / columns,
height = height - height / rows,
rows = r,
columns = c
);
}
}
.extrude(base_height - THICKNESS);
cap = Rect(width, height).extrude(THICKNESS);
knobs = Circle(d = 4.8mm)
.multiply(rows * columns)
.distribute_grid(width, height, rows, columns)
.extrude(1.7mm);
{ base; cap; knobs; }.align(Z).union();
}
n = 4;
LegoBrick(
rows = [1..n],
columns = [1..n],
base_height = BASE_HEIGHT * [1 / 3, 100%, 200%, 300%]
)
.distribute_grid(cell_size = n * 10mm,
rows = 2*n,
columns = 2*n,
);
