Browse Source

gradients example using streaming api

v1.x
Tj Holowaychuk 14 years ago
parent
commit
b2179920e3
  1. 10
      examples/gradients.js

10
examples/gradients.js

@ -5,7 +5,8 @@
var Canvas = require('../lib/canvas') var Canvas = require('../lib/canvas')
, canvas = new Canvas(320, 320) , canvas = new Canvas(320, 320)
, ctx = canvas.getContext('2d'); , ctx = canvas.getContext('2d')
, fs = require('fs');
// Create gradients // Create gradients
var lingrad = ctx.createLinearGradient(0,0,0,150); var lingrad = ctx.createLinearGradient(0,0,0,150);
@ -26,4 +27,9 @@ ctx.strokeStyle = lingrad2;
ctx.fillRect(10,10,130,130); ctx.fillRect(10,10,130,130);
ctx.strokeRect(50,50,50,50); ctx.strokeRect(50,50,50,50);
canvas.savePNG(__dirname + '/gradients.png'); var out = fs.createWriteStream(__dirname + '/gradients.png')
, stream = canvas.createPNGStream();
stream.on('data', function(chunk){
out.write(chunk);
});
Loading…
Cancel
Save