-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
119 lines (111 loc) · 3.81 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3: Number Devil Pascal's Triangle</title>
<script type="text/javascript" src="d3/d3.js"></script>
<script type="text/javascript" src="bignumber.min.js"></script>
<style type="text/css">
/* No style rules here yet */
</style>
</head>
<body>
<label for="mod_y"
style="display: inline-block; width: 240px; text-align: right">
yellow = mod(<span id="modY-value">32</span>)
</label>
<input type="range" min="2" max="128" id="modY">
<label for="mod_b"
style="display: inline-block; width: 240px; text-align: right">
blue = mod(<span id="modB-value">2</span>)
</label>
<input type="range" min="2" max="128" id="modB">
<!--
1
1 1
1 2 1
1 3 3 1
how many rows: ___ show divisible by: ___
[ { row: 1, col: 1, val: 1, x: 245, y: 0, divisibleByTwo: false },
{ row: 2, col: 1, val: 1, x: 230, y: 20, divisibleByTwo: false },
{ row: 2, col: 2, val: 1, x: 260, y: 20, divisibleByTwo: true },
{ row: 3, col: 1, val: 1, }..
]
-->
<script type="text/javascript">
//Width and height
var w = 720;
var h = 720;
var numRows = 64*2;
var cellSize = h/numRows;
var one = new BigNumber(1);
var dataset = [[one], [one,one]];
for(var i = 2; i < numRows; i++) {
dataset.push([]);
dataset[i].push(one);
for(var j = 0; j < (i-1); j++) {
var dp = dataset[i-1][j].plus(dataset[i-1][j+1]);
dataset[i].push(dp);
}
dataset[i].push(one);
}
var cell_data = [];
for(var i = 0; i < numRows; i++) {
for(var j = 0; j <= i; j++) {
cell_data.push(
{
row: i+1,
col: j+1,
val: dataset[i][j]
}
);
}
}
//Create SVG element
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
var cells = svg.selectAll("rect")
.data(cell_data)
.enter()
.append("rect")
.attr("x", function(d) {
return w/2-(d.row*cellSize)/2+(d.col-1)*cellSize;
})
.attr("y", function(d) {
return (d.row-1)*cellSize;
})
.attr("width", cellSize)
.attr("height", cellSize)
.attr("stroke", "navy")
.attr("stroke-width", 1);
var modB = 2;
var modY = 32;
function update() {
d3.select("#modB-value").text(modB);
d3.select("#modY-value").text(modY);
d3.select("#modB").property("value", modB);
d3.select("#modY").property("value", modY);
d3.selectAll("rect").attr("fill", function(d) {
if(d.val.mod(modY) == 0) {
return "yellow";
}
if(d.val.mod(modB) == 0) {
return "blue";
}
return "red";
});
}
update();
d3.select("#modB").on("input", function() {
modB = +this.value;
update();
});
d3.select("#modY").on("input", function() {
modY = +this.value;
update();
})
</script>
</body>
</html>