peabrainiac.github.io/GifScripter
Save script
Load script
Output:
Run ▶
const TOTAL_FRAMES = 72;
const WIDTH = 480;
const HEIGHT = 360;
const ZOOM = 75;
const ITERATIONS = 30;
var frame = 0;
var imgData = GifWriter.createImageData(WIDTH,HEIGHT);
computeNextFrame();
function computeNextFrame(){
if (frame<TOTAL_FRAMES){
var px,py,cx,cy,x,y,x2,y2,i,c,r,g,b,pi;
var rx = Math.cos(2*Math.PI*frame/TOTAL_FRAMES);
var ry = Math.sin(2*Math.PI*frame/TOTAL_FRAMES);
for (px=0;px<WIDTH;px++){
for (py=0;py<HEIGHT;py++){
cx = (px-WIDTH/2)/ZOOM;
cy = (py-HEIGHT/2)/ZOOM;
x = 0;
y = 0;
for (i=0;i<ITERATIONS&&x*x+y*y<4;i++){
x2 = x*x-y*y;
y2 = 2*x*y;
x = Math.abs(x2*rx-y2*ry+cx);
y = Math.abs(y2*rx+x2*ry+cy);
}
c = (i<ITERATIONS)?Utils.hslToRgb(i/(5*ITERATIONS),0.75,i/ITERATIONS):[0,0,0];
pi = (px+py*WIDTH)*4;
imgData.data[pi] = c[0]*255;
imgData.data[pi+1] = c[1]*255;
imgData.data[pi+2] = c[2]*255;
imgData.data[pi+3] = 255;
}
}
frame++;
GifWriter.addFrame(imgData).then(computeNextFrame);
}else{
GifWriter.finish();
}
}