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 + });