-
Notifications
You must be signed in to change notification settings - Fork 0
/
intro.html
47 lines (39 loc) · 1.06 KB
/
intro.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
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>
var mouse = [480, 250],
count = 0;
var svg = d3.select("body").append("svg")
.attr("width", 960)
.attr("height", 500);
var g = svg.selectAll("g")
.data(d3.range(25))
.enter().append("g")
.attr("transform", "translate(" + mouse + ")");
g.append("rect")
.attr("rx", 6)
.attr("ry", 6)
.attr("x", -12.5)
.attr("y", -12.5)
.attr("width", 25)
.attr("height", 25)
.attr("transform", function(d, i) { return "scale(" + (1 - d / 25) * 20 + ")"; })
.style("fill", d3.scale.category20c());
g.datum(function(d) {
return {center: mouse.slice(), angle: 0};
});
svg.on("mousemove", function() {
mouse = d3.mouse(this);
});
d3.timer(function() {
count++;
g.attr("transform", function(d, i) {
d.center[0] += (mouse[0] - d.center[0]) / (i + 5);
d.center[1] += (mouse[1] - d.center[1]) / (i + 5);
d.angle += Math.sin((count + i) / 10) * 7;
return "translate(" + d.center + ")rotate(" + d.angle + ")";
});
});
</script>