-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathicosahedron-3055104.html
106 lines (89 loc) · 2.42 KB
/
icosahedron-3055104.html
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
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.point {
fill: #000;
stroke: #fff;
}
.edge {
fill: none;
stroke: #000;
stroke-opacity: .4;
}
.face {
fill: #eee;
}
</style>
<body>
<script src="http://d3js.org/d3.v2.min.js?2.9.6"></script>
<script>
var width = 960,
height = 500;
var origin = [0, 0],
velocity = [.18, .06];
var projection = d3.geo.azimuthal()
.mode("orthographic")
.origin(origin)
.scale(240);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var face = svg.selectAll(".face")
.data(icosahedron_faces)
.enter().append("path")
.attr("class", "face");
var edge = svg.selectAll(".edge")
.data(icosahedron_edges)
.enter().append("path")
.attr("class", "edge");
var point = svg.selectAll(".point")
.data(icosahedron_points)
.enter().append("circle")
.attr("class", "point")
.attr("r", 3.5);
d3.timer(function() {
origin[0] += velocity[0];
origin[1] += velocity[1];
projection.origin(origin);
draw();
});
function icosahedron_points() {
var points = [],
y = Math.atan2(1, 2) * 180 / Math.PI;
points.push([0, -90]);
for (var x = 0; x < 360; x += 36) {
points.push([x, -y], [x += 36, y]);
}
points.push([0, 90]);
return points;
}
function icosahedron_edges() {
var edges = [],
y = Math.atan2(1, 2) * 180 / Math.PI;
for (var x = 0; x < 360; x += 72) {
edges.push([[x + 0, -90], [x + 0, -y]]);
edges.push([[x + 0, -y], [x + 72, -y]]);
edges.push([[x + 36, y], [x - 36, y]]);
edges.push([[x + 36, y], [x + 0, -y]]);
edges.push([[x - 36, y], [x + 0, -y]]);
edges.push([[x + 36, 90], [x + 36, y]]);
}
return edges;
}
function icosahedron_faces() {
var faces = [],
y = Math.atan2(1, 2) * 180 / Math.PI;
for (var x = 0; x < 360; x += 72) {
faces.push([[x + 0, -90], [x + 0, -y], [x + 72, -y], [x + 0, -90]]);
faces.push([[x + 0, -y], [x + 72, -y], [x + 36, y], [x + 0, -y]]);
faces.push([[x + 36, y], [x + 0, -y], [x - 36, y], [x + 36, y]]);
faces.push([[x - 36, 90], [x - 36, y], [x + 36, y], [x + 36, 90]]);
}
return faces;
}
function draw() {
point.attr("transform", function(d) { return "translate(" + projection(d) + ")"; });
edge.attr("d", function(d) { return "M" + d.map(projection).join("L"); });
face.attr("d", function(d) { return "M" + d.map(projection).join("L"); });
}
</script>