# 一個拼圖片

``````length = 20;
spacing = 0.5;

p_offset = length * 9 / 16 + spacing / 2;
n_offset = -length * 7 / 16 - spacing / 2;
convex_radius = length / 8 - spacing / 2;
concave_radius = length / 8 + spacing / 2;

\$fn = 24;

difference() {
union() {
square(length, center = true);
translate([p_offset, 0])
translate([0, p_offset])
}

translate([n_offset, 0])
translate([0, n_offset])
}
``````

# 很多拼圖片

``````length = 20;
spacing = 0.5;
x_puzzles = 11;
y_puzzles = 6;

module puzzle_piece(length, spacing = 0.5) {
p_offset = length * 9 / 16 + spacing / 2;
n_offset = -length * 7 / 16 - spacing / 2;

convex_radius = length / 8 - spacing / 2;
concave_radius = length / 8 + spacing / 2;

\$fn = 24;

translate([length / 2, length / 2]) difference() {
union() {
square(length, center = true);
translate([p_offset, 0])
translate([0, p_offset])
}

translate([n_offset, 0])
translate([0, n_offset])
}
}

for(x = [0:x_puzzles - 1]) {
for(y = [0:y_puzzles - 1]) {
translate([x * (length + spacing), y * (length + spacing)])
puzzle_piece(length, spacing = 0.5);
}
}
``````

# 修邊

``````length = 20;
spacing = 0.5;
x_puzzles = 10;
y_puzzles = 5;

module puzzle_piece(length, spacing = 0.5) {
p_offset = length * 9 / 16 + spacing / 2;
n_offset = -length * 7 / 16 - spacing / 2;

convex_radius = length / 8 - spacing / 2;
concave_radius = length / 8 + spacing / 2;

\$fn = 24;

translate([length / 2, length / 2]) difference() {
union() {
square(length, center = true);
translate([p_offset, 0])
translate([0, p_offset])
}

translate([n_offset, 0])
translate([0, n_offset])
}
}

module puzzle(x_puzzles, y_puzzles, length, spacing = 0.5) {
intersection() {
square([
x_puzzles * (length + spacing) - spacing,
y_puzzles * (length + spacing) - spacing]
);

for(x = [0:x_puzzles - 1]) {
for(y = [0:y_puzzles - 1]) {
translate([x * (length + spacing), y * (length + spacing)])
union() {
puzzle_piece(length, spacing = 0.5);
if(x == 0) {
translate([0, length / 2])
circle(length / 4, \$fn = 24);
}
if(y == 0) {
translate([length / 2, 0])
circle(length / 4, \$fn = 24);
}
}
}
}
}
}

puzzle(x_puzzles, y_puzzles, length, spacing);
``````