Skip to content

Instantly share code, notes, and snippets.

@ikr7
Created September 23, 2014 14:31
Show Gist options
  • Save ikr7/2e85b335a2d089b45c61 to your computer and use it in GitHub Desktop.
Save ikr7/2e85b335a2d089b45c61 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var Canvas = require('canvas');
var GIFEncoder = require('gifencoder');
var w = 142;
var h = 179;
var cvs = new Canvas(w, h);
var ctx = cvs.getContext('2d');
var ginkosan = new Canvas.Image();
ginkosan.src = fs.readFileSync('./ginkosan.png');
var encoder = new GIFEncoder(w, h);
encoder.start();
encoder.setRepeat(0);
encoder.setDelay(5);
ctx.fillStyle = 'white';
for(var i = 0; i < 360; i += 10){
ctx.fillRect(0, 0, w, h);
ctx.translate(w / 2, h / 2);
ctx.rotate(i / 180 * Math.PI);
ctx.translate(-w / 2, -h / 2);
ctx.drawImage(ginkosan, 0, 0);
encoder.addFrame(ctx);
}
encoder.finish();
fs.writeFileSync('./anime.gif', encoder.out.getData());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment