From ef6a8fb36dc6bd7786381f008994993b21c04289 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Wed, 3 Nov 2010 14:32:18 -0700 Subject: [PATCH] Remaining examples using streaming apu --- examples/clock.js | 10 ++++++++-- examples/globalAlpha.js | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/examples/clock.js b/examples/clock.js index 3c568c2..4ed77cc 100644 --- a/examples/clock.js +++ b/examples/clock.js @@ -5,7 +5,8 @@ var Canvas = require('../lib/canvas') , canvas = new Canvas(320, 320) - , ctx = canvas.getContext('2d'); + , ctx = canvas.getContext('2d') + , fs = require('fs'); function getX(angle) { return -Math.sin(angle + Math.PI); @@ -104,4 +105,9 @@ function clock(ctx){ clock(ctx); -canvas.savePNG(__dirname + "/clock.png"); \ No newline at end of file +var out = fs.createWriteStream(__dirname + '/clock.png') + , stream = canvas.createPNGStream(); + +stream.on('data', function(chunk){ + out.write(chunk); +}); \ No newline at end of file diff --git a/examples/globalAlpha.js b/examples/globalAlpha.js index 457cd30..4d79e24 100644 --- a/examples/globalAlpha.js +++ b/examples/globalAlpha.js @@ -5,7 +5,8 @@ var Canvas = require('../lib/canvas') , canvas = new Canvas(150, 150) - , ctx = canvas.getContext('2d'); + , ctx = canvas.getContext('2d') + , fs = require('fs'); ctx.fillStyle = '#FD0'; ctx.fillRect(0,0,75,75); @@ -27,4 +28,9 @@ for (i=0;i<7;i++){ ctx.fill(); } -canvas.savePNG(__dirname + '/globalAlpha.png'); \ No newline at end of file +var out = fs.createWriteStream(__dirname + '/globalAlpha.png') + , stream = canvas.createPNGStream(); + +stream.on('data', function(chunk){ + out.write(chunk); +}); \ No newline at end of file