forked from JustinSDK/dotSCAD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiplication_puzzle..scad
107 lines (92 loc) · 3.26 KB
/
multiplication_puzzle..scad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
piece_side_length = 25;
// for n x n multiplication puzzle
n = 9; // [1:9]
spacing = 0.5;
module puzzle_piece(side_length, spacing) {
$fn = 48;
circle_radius = side_length / 10;
half_circle_radius = circle_radius / 2;
half_side_length = side_length / 2;
side_length_div_4 = side_length / 4;
bulge_circle_radius = circle_radius - spacing;
circle_x = half_circle_radius - half_side_length - spacing;
circle_y = side_length_div_4 - half_side_length;
circle_y2 = side_length_div_4 * 3 - half_side_length;
module df_circles() {
translate([circle_x, circle_y])
circle(circle_radius);
translate([circle_x, circle_y2])
circle(circle_radius);
}
module bulge_circles() {
translate([side_length + circle_x, circle_y])
circle(bulge_circle_radius);
translate([side_length + circle_x, circle_y2])
circle(bulge_circle_radius);
}
translate([half_side_length - spacing, half_side_length - spacing]) {
difference() {
square(side_length - spacing, center = true);
// left
df_circles();
// top
rotate(-90)
df_circles();
}
// right
bulge_circles();
// bottom
rotate(-90)
bulge_circles();
}
}
module puzzle_piece_with_text(side_length, text, spacing) {
half_side_length = side_length / 2;
difference() {
puzzle_piece(side_length, spacing);
translate([half_side_length, half_side_length])
rotate(-45)
text(text, size = side_length / 3, halign = "center", valign = "center");
}
}
module multiplication_puzzle(n, piece_side_length, spacing) {
$fn = 48;
circle_radius = piece_side_length / 10;
half_circle_radius = circle_radius / 2;
side_length_div_4 = piece_side_length / 4;
n_minus_one = n - 1;
intersection() {
union() for(x = [0 : n_minus_one]) {
for(y = [0 : n_minus_one]) {
pos = [piece_side_length * x, piece_side_length * y];
r = (x + 1) * (y + 1);
linear_extrude(r) union() {
translate(pos)
puzzle_piece_with_text(piece_side_length, str(r), spacing);
if(x == 0) {
x_offset = half_circle_radius - spacing * 2;
y_offset = piece_side_length * y - spacing;
translate([x_offset, side_length_div_4 + y_offset, 0])
circle(circle_radius);
translate([x_offset, side_length_div_4 * 3 + y_offset, 0])
circle(circle_radius);
}
if(y == n_minus_one) {
x_offset = piece_side_length * x - spacing;
y_offset = piece_side_length * (y + 1) - half_circle_radius;
translate([side_length_div_4 + x_offset, y_offset])
circle(circle_radius);
translate([side_length_div_4 * 3 + x_offset, y_offset])
circle(circle_radius);
}
}
linear_extrude(r - 0.6)
translate(pos)
puzzle_piece(piece_side_length, spacing);
}
}
linear_extrude(n * n)
square(piece_side_length * n - spacing * 1.5);
}
}
multiplication_puzzle(n, piece_side_length, spacing);