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

46
node_modules/ansi/examples/imgcat.js generated vendored Executable file
View file

@ -0,0 +1,46 @@
#!/usr/bin/env node
var ansi = require('../')
, cursor = ansi(process.stdout)
, tty = require('tty')
, Canvas = require('canvas')
, imageFile = process.argv[2] || __dirname + '/yoshi.png'
, image = require('fs').readFileSync(imageFile)
, pixel = ' '
, alphaThreshold = 0
var img = new Canvas.Image();
img.src = image;
function draw () {
var width = process.stdout.getWindowSize()[0] / pixel.length | 0
, 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 > alphaThreshold) {
cursor.bg.rgb(r, g, b);
} else {
cursor.bg.reset();
}
process.stdout.write(pixel);
if ((i/4|0) % w === (w-1)) {
cursor.bg.reset();
process.stdout.write('\n');
}
}
}
draw();