-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrotating-intersecting-stars.js
73 lines (63 loc) · 1.58 KB
/
rotating-intersecting-stars.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function main () {
var shapes = []
for(var j=4; j>1; j--){
shapes.push(
rotate([0,0,j * 10],
hollowStar(j,j /2.5,0.8,(5 - j)/3,7)))
}
return union(shapes)
}
function star(r,ir, h, sides) {
var points = [];
var delta = Math.PI / sides;
for(var i=0; i<sides; i++) {
// outer, then inner
points.push([
r * Math.cos(2*i*delta),
r * Math.sin(2*i*delta)
])
points.push([
ir * Math.cos((2*i + 1)*delta),
ir * Math.sin((2*i + 1)*delta)
])
}
console.log(points)
return linear_extrude({height: h},
polygon(points)
)
}
function hollowStar(r,ir, w, h, sides) {
var points = [];
var delta = Math.PI / sides;
for(var i=0; i<sides; i++) {
// outer, then inner
points.push([
r * Math.cos(2*i*delta),
r * Math.sin(2*i*delta)
])
points.push([
ir * Math.cos((2*i + 1)*delta),
ir * Math.sin((2*i + 1)*delta)
])
}
var ipoints = [];
for(i=0; i<sides; i++) {
// outer, then inner
ipoints.push([
(r *w) * Math.cos(2*i*delta),
(r *w) * Math.sin(2*i*delta)
])
ipoints.push([
(ir *w) * Math.cos((2*i + 1)*delta),
(ir *w) * Math.sin((2*i + 1)*delta)
])
}
return difference(
linear_extrude({height: h},
polygon(points)
),
linear_extrude({height: h},
polygon(ipoints)
)
)
}