Skip to content

Instantly share code, notes, and snippets.

@Southclaws
Created May 20, 2014 15:03
Show Gist options
  • Save Southclaws/7651a5eb903356d00000 to your computer and use it in GitHub Desktop.
Save Southclaws/7651a5eb903356d00000 to your computer and use it in GitHub Desktop.
Generates a heatmap from coordinates loaded from "coords-list.txt".
var heatmap = require('heatmap');
var fs = require('fs');
var heat = heatmap(6000, 6000, { radius : 30 });
fs.readFile('coords-list.txt', 'utf8', function(error, data)
{
var arr = data.split("\r\n");
for (var i = 0; i < arr.length; i++)
{
var xy = arr[i].split(", ");
console.log("x: "+(parseInt(xy[0]) + 3000)+" y: "+(6000 - (parseInt(xy[1]) + 3000)));
heat.addPoint(parseInt(xy[0]) + 3000, 6000 - (parseInt(xy[1]) + 3000));
};
console.log("executing: heat.draw");
heat.draw();
console.log("executing: fs.writeFileSync");
fs.writeFileSync('blob.png', heat.canvas.toBuffer());
console.log("Done!");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment