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
|
size(200);
import palette;
import three;
triple[] M={
(-1,-1,-1),(0,-1,-1),(1,-1,-1),(1,0,-1),
(1,1,-1),(0,1,-1),(-1,1,-1),(-1,0,-1),
(-1,-1,0),(1,-1,0),(1,1,0),(-1,1,0),
(-1,-1,1),(0,-1,1),(1,-1,1),(1,0,1),
(1,1,1),(0,1,1),(-1,1,1),(-1,0,1)
};
triple[] K={
(1,-1,-1),(1,0,-1),(1,1,-1),(1,1,0),
(1,1,1),(1,0,1),(1,-1,1),(1,-1,0),
(0,0,-1),(0,0,1),(0,-1,0),(0,1,0)
};
surface s;
void recur(triple p, real u, int level) {
if(level > 1 )
for(triple V : M)
recur(p+u*V,u/3,level-1);
else
for(triple V : K) {
transform3 T=shift(p)*scale3(u)*shift(V)*scale3(0.5);
surface t=T*surface((1,-1,-1)--(1,1,-1)--(1,1,1)--(1,-1,1)--cycle);
s.append(t);
s.append(scale3(-1)*t);
}
}
recur((0,0,0),1/3,3);
surface sf;
sf.append(s);
sf.append(rotate(90,Y)*s);
sf.append(rotate(90,Z)*s);
sf.colors(palette(sf.map(abs),Rainbow()));
draw(sf);
|