Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created August 14, 2012 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/3349907 to your computer and use it in GitHub Desktop.
Save tmcw/3349907 to your computer and use it in GitHub Desktop.
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