Created
March 26, 2013 19:11
-
-
Save tmcw/5248264 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Canvas = require('canvas'), | |
fs = require('fs'); | |
var keystrokes = fs.readFileSync('../allkeysnew.log', 'utf8'); | |
var lines = keystrokes.split('\n').slice(1); | |
var width = 2880, | |
height = 1800, | |
c = new Canvas(width, height), | |
ctx = c.getContext('2d'), | |
gaps = {}, | |
days = []; | |
ctx.fillStyle = '#000'; | |
ctx.fillRect(0, 0, width, height); | |
function secs(d) { | |
return (d.getHours() * 60 * 60) + | |
(d.getMinutes() * 60) + | |
(d.getSeconds()); | |
} | |
function stamp(d) { | |
return d.getDate() + ',' + d.getMonth() + '-' + d.getYear(); | |
} | |
var days = {}; | |
for (var i = 0; i < lines.length; i++) { | |
var t = new Date(+lines[i].split(',')[0] * 1000); | |
var v = +lines[i].split(',')[1]; | |
var s = stamp(t); | |
if (!days[s]) days[s] = []; | |
days[s].push([secs(t), v]); | |
} | |
var full = (60 * 60 * 24); | |
function sy(x) { | |
return Math.floor((x / full) * height); | |
} | |
var ndays = Object.keys(days).length; | |
function sx(x) { | |
return (x / ndays) * width; | |
} | |
var wid = 8; | |
var scale = ['#111', | |
'#223', | |
'#336', | |
'#45a', | |
'#76e', | |
'#99f', | |
'#FF8AFF', | |
'#faf']; | |
var dayn = 0; | |
ctx.globalAlpha = 1; | |
console.log(Object.keys(days).length); | |
for (var d in days) { | |
var day = days[d]; | |
for (var t = 0; t < day.length; t++) { | |
var v = day[t][1]; | |
var sv = Math.max(0, Math.min(Math.sqrt(v) / 4, 8)); | |
ctx.fillStyle = '#fff'; // scale[sv]; | |
ctx.fillRect(~~sx(dayn), ~~sy(day[t][0]), wid, 3); | |
} | |
dayn++; | |
} | |
fs.writeFileSync('basically_five.png', c.toBuffer()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment