Commit node_modules.

For @billywhizz :)

And cause it's just an all around good idea for command-line apps.
This commit is contained in:
Nathan Rajlich 2012-02-10 23:44:09 -08:00
parent d39620999f
commit 24bde139e1
255 changed files with 20261 additions and 0 deletions

51
node_modules/ansi/server.js generated vendored Normal file
View file

@ -0,0 +1,51 @@
var http = require('http')
, ansi = require('./')
, Canvas = require('canvas')
, Image = Canvas.Image
, imageFile = process.argv[2] || __dirname + '/examples/yoshi.png'
, image = require('fs').readFileSync(imageFile)
var img = new Image()
img.src = image
var server = http.createServer(function (req, res) {
draw(res);
})
server.listen(8080, function () {
console.error('HTTP server listening on:', this.address())
})
function draw (stream) {
var cursor = ansi(stream)
, pixel = ' '
, width = img.width
, scaleW = img.width > width ? width / img.width : 1
, w = Math.floor(img.width * scaleW)
, h = Math.floor(img.height * scaleW);
var canvas = new Canvas(w, h)
, ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0, w, h);
var data = ctx.getImageData(0, 0, w, h).data;
for (var i=0, l=data.length; i<l; i+=4) {
var r = data[i]
, g = data[i+1]
, b = data[i+2]
, alpha = data[i+3];
if (alpha > 0) {
cursor.bg.rgb(r, g, b);
} else {
cursor.bg.reset();
}
stream.write(pixel);
if ((i/4|0) % w === (w-1)) {
cursor.bg.reset();
stream.write('\n');
}
}
stream.end();
}