Skip to content
Browse files

use a mask to add heat and remove some hardcoding.

  • Loading branch information...
1 parent 5655c0f commit 64c04f51d8ed666468fb63467b47153df8405b78 mpd committed May 12, 2010
Showing with 16 additions and 7 deletions.
  1. +16 −7 heatmap.js
View
23 heatmap.js
@@ -7,36 +7,45 @@ $(function () {
smoothHeat,
renderHeat,
toHue,
- hueToRGB;
+ hueToRGB,
+ heatMask;
+
+ // mask we apply to a point that is moused over.
+ heatMask = [
+ [0, 1, 0],
+ [1, 3, 1],
+ [0, 1, 0]
+ ];
canvas.attr({
width: $('#result').width(),
height: $('#result').height()
});
$('#trackme').mousemove(function (event) {
- var key, eventX, eventY, i, j;
+ var key, eventX, eventY, i, j, initialI, initialJ;
eventX = event.pageX - this.offsetLeft;
eventY = event.pageY - this.offsetTop;
- for (i = eventX - 1; i <= eventX + 1; i += 1) {
+ initialI = eventX - 1;
+ initialJ = eventY - 1;
+
+ for (i = initialI; i <= eventX + 1; i += 1) {
if (i < 0) {
continue;
}
- for (j = eventY - 1; j <= eventY + 1; j += 1) {
+ for (j = initialJ; j <= eventY + 1; j += 1) {
if (j < 0) {
continue;
}
key = i + "," + j;
heat[key] = heat[key] || 0;
- heat[key] += 1;
+ heat[key] += heatMask[i - initialI][j - initialJ];
}
}
-
- heat[eventX + "," + eventY] += 2;
});
setInterval(function () {

0 comments on commit 64c04f5

Please sign in to comment.
Something went wrong with that request. Please try again.