Created
May 10, 2013 20:44
-
-
Save tmcw/5557251 to your computer and use it in GitHub Desktop.
Create dissolve effect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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