-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
61 lines (51 loc) · 1.8 KB
/
index.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
<!doctype html>
<html>
<body>
<a href="http://github.com/sylvaingi/d3-life"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://a248.e.akamai.net/assets.github.com/img/abad93f42020b733148435e2cd92ce15c542d320/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub"></a>
<style type="text/css">
html,body{
margin: 0;
overflow: hidden;
}
circle {
fill: #1f77b4;
}
</style>
<script type="text/javascript" src="js/Cell.js"></script>
<script type="text/javascript" src="js/CellGrid.js"></script>
<script type="text/javascript" src="js/d3.v2.js"></script>
<script type="text/javascript">
(function(){
var w = window.innerWidth,
h = window.innerHeight,
columns = 10,
rows = 10,
wRatio = w/columns,
hRatio = h/rows,
radius = Math.min(Math.floor(w/(2*columns)),Math.floor(h/(2*rows)));
var grid = new CellGrid(rows,columns);
grid.reset();
var svg = d3.select("body").append("svg:svg")
.attr("width", w)
.attr("height", h);
var circle = svg.selectAll("circle");
(function(){
grid.step();
circle = circle.data(grid.aliveCells(),function(d){return d.n});
circle.enter().append("circle")
.attr("cx", function(d){return d.x*wRatio + radius})
.attr("cy", function(d){return d.y*hRatio + radius})
.transition().duration(500)
.attr("r", radius)
.style("fill","#2ca02c");;
circle.exit()
.style("fill","#d62728")
.transition().duration(500)
.attr("r", 0)
.remove();
setTimeout(arguments.callee,500);
})();
})();
</script>
</body>
</html>