Created
August 14, 2012 14:43
-
-
Save tmcw/3349907 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'), | |
c = new Canvas(1280, 140), | |
ctx = c.getContext('2d'); | |
var td = '/Users/tmcw/Dropbox/docs/twitter/tweets/'; | |
var tweets = fs.readdirSync(td); | |
function sx(x) { | |
return ((x / (24 * 60)) * 1280); | |
} | |
ctx.fillStyle = '#fff'; | |
ctx.fillRect(0, 0, 1280, 140); | |
ctx.fillStyle = '#000'; | |
var t; | |
for (var i = 0; i < 24; i++) { | |
if (i == 0) t = '12am'; | |
else if (i == 12) t = '12pm'; | |
else if (i > 12) { | |
t = (i - 12) + 'pm'; | |
} else { | |
t = (i) + 'am'; | |
} | |
ctx.fillText(t, sx(i * 60), 130); | |
} | |
ctx.globalAlpha = 0.1; | |
tweets.forEach(function(t) { | |
var twt = JSON.parse(fs.readFileSync(td + t, 'utf8')); | |
var time = new Date(twt.created_at); | |
var x = (time.getHours() * 60) + time.getMinutes(); | |
ctx.fillRect(sx(x), 0, 1, 120); | |
}); | |
c.toBuffer(function(err, buf) { | |
fs.writeFileSync('twitter.png', buf); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment