-
Notifications
You must be signed in to change notification settings - Fork 1
/
sliced-hex-gapped-six.js
56 lines (51 loc) · 1.11 KB
/
sliced-hex-gapped-six.js
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
function main() {
var shapes = [];
for (var i = 0; i < 7; i++) {
for (var j = 0; j < 7; j++) {
if (Math.random() > 0.25)
shapes.push(hex(1 + 5 * cos(20 * (3 - i)) * cos(20 * (3 - j)), i, j));
}
}
return union(shapes);
}
var pit = Math.PI / 3;
var dv = Math.sin(pit);
var dh = 1;
function hex(h, x, y) {
var dx, dy;
if (x % 2 == 0) {
dx = x * 1.5 * dh;
dy = y * 2 * dv;
} else {
dx = x * 1.5 * dh;
dy = y * dv * 2 + dv;
}
return translate(
[dx, dy, 0],
difference(
linear_extrude(
{ height: h },
polygon([
[1, 0],
[Math.cos(pit), Math.sin(pit)],
[-Math.cos(pit), Math.sin(pit)],
[-1, 0],
[-Math.cos(pit), -Math.sin(pit)],
[Math.cos(pit), -Math.sin(pit)]
])
),
slice(h)
)
);
}
function slice(h) {
return Math.random() > 0.5
? translate(
[1, 0, h + 1],
rotate([0, 22.5, 0], cube({ size: [4, 4, 4], center: true }))
)
: translate(
[0, -1, h + 1],
rotate([22.5, 0, 0], cube({ size: [4, 4, 4], center: true }))
);
}