Starburst
float cx,cy;
int[] screenBuf;
PImage[] frames;
int cycleLength = 48;
void setup()
{
size(500,500);
loadPixels();
cx = width/2;
cy = height/2;
frames = new PImage[cycleLength];
frameRate(24);
}
void draw()
{
if (frameCount <= cycleLength) {
// Do slow computation, and save frame
float t = frameCount*TWO_PI/cycleLength;
int n = 0;
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
float d = log(dist(x,y,cx,cy));
float a = atan2(y-cy, x-cx);
float r = sin(d*8+a) * sin(a*3);
float g = sin(d*8+a-HALF_PI-t ) * sin(a*5);
float b = sin(d*8+a+HALF_PI+t ) * sin(a*7);
r = r*128+128;
g = g*128+128;
b = b*128+128;
pixels[n] = color(r,g,b);
n++;
}
}
updatePixels();
frames[frameCount % cycleLength] = get();
}
else {
// Play back saved frame
image(frames[frameCount % cycleLength],0,0);
}
}