forked from pyalot/webgl-heatmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
73 lines (68 loc) · 2.69 KB
/
example.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
<!DOCTYPE html>
<html>
<head>
<script src="webgl-heatmap.js"></script>
<script type="text/javascript">
window.onload = function(){
var canvas = document.getElementsByTagName('canvas')[0];
var heatmap = createWebGLHeatmap({canvas: canvas});
//var heatmap = createWebGLHeatmap({width: 500, height: 500}); // statically sized heatmap
// just feeding some mouse coords
document.body.appendChild(heatmap.canvas);
canvas.onmousemove = function(event){
var x = event.offsetX || event.clientX;
var y = event.offsetY || event.clientY;
//heatmap.addPoint(x, y, 100, 10/255);
var count = 0;
while(count < 200){
var xoff = Math.random()*2-1;
var yoff = Math.random()*2-1;
var l = xoff*xoff + yoff*yoff;
if(l > 1){
continue;
}
var ls = Math.sqrt(l);
xoff/=ls; yoff/=ls;
xoff*=1-l; yoff*=1-l;
count += 1;
heatmap.addPoint(x+xoff*50, y+yoff*50, 20, 1/300);
}
}
canvas.onclick = function(){
heatmap.clear();
}
var raf = window.requestAnimationFrame || window.mozRequestAnimationFrame;
var update = function(){
heatmap.adjustSize(); // can be commented out for statically sized heatmaps, resize clears the map
heatmap.update(); // adds the buffered points
heatmap.display(); // adds the buffered points
//heatmap.multiply(0.9995);
//heatmap.blur();
//heatmap.clamp(0.0, 1.0); // depending on usecase you might want to clamp it
raf(update);
}
raf(update);
}
</script>
<style type="text/css">
body,html,canvas{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
font-family: sans-serif;
color: black;
overflow: hidden;
}
div.controls{
font-weight: bold;
position: absolute;
top: 10px;
left: 10px;
}
</style>
</head>
<body>
<canvas></canvas>
</body>
</html>