Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created May 10, 2013 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/5557251 to your computer and use it in GitHub Desktop.
Save tmcw/5557251 to your computer and use it in GitHub Desktop.
Create dissolve effect
var Canvas = require('canvas'),
fs = require('fs'),
pad = require('pad'),
_ = require('underscore'),
canvas = new Canvas(256, 256),
ctx = canvas.getContext('2d');
ctx.antialias = 'none';
var pts = _.range(256 * 256).sort(function() { return Math.random() - 0.5; });
ctx.fillStyle = '#fff';
ctx.fillRect(0, 0, 256, 256);
ctx.fillStyle = '#000';
var f = 8;
for (var i = 0; i < 256 * 256; i++) {
var tofill = pts.pop();
ctx.fillRect(Math.floor(tofill / 256), tofill % 256, 1, 1);
if (i % (256 * 32) === 0) {
fs.writeFileSync('frames/' + pad(15, (f--) + 'frame.png', '0'), canvas.toBuffer());
}
}
fs.writeFileSync('frames/' + pad(15, (f--) + 'frame.png', '0'), canvas.toBuffer());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment