From 45033d40316d1281979e26619df5cdecc9c6015f Mon Sep 17 00:00:00 2001 From: Luke Page Date: Fri, 9 Oct 2015 07:49:42 +0100 Subject: [PATCH] expand example to create a new file --- examples/newfile.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/examples/newfile.js b/examples/newfile.js index 71153ed..77ea5b6 100644 --- a/examples/newfile.js +++ b/examples/newfile.js @@ -1,10 +1,23 @@ var PNG = require("../lib/png").PNG; -(new PNG({width:1,height:1})).pack() - .on('data', function(data) { - console.log('data', data); - }) - .on('end', function() { +var newfile = new PNG({width:10,height:10}); + +for (var y = 0; y < png.height; y++) { + for (var x = 0; x < png.width; x++) { + var idx = (png.width * y + x) << 2; + + var col = x < (png.width >> 1) ^ y < (png.height >> 1) ? 0xe5 : 0xff; + + png.data[idx] = col; + png.data[idx + 1] = col; + png.data[idx + 2] = col; + png.data[idx + 3] = 0xff; + } +} + +newfile.pack() + .pipe(fs.createWriteStream(__dirname + '/newfile.png')) + .on('finish', function() { console.log('bitmap:', this.data); console.log('end !'); - }); \ No newline at end of file + });