Skip to content

Instantly share code, notes, and snippets.

@reuk
Created January 19, 2014 17:09
Show Gist options
  • Save reuk/8507723 to your computer and use it in GitHub Desktop.
Save reuk/8507723 to your computer and use it in GitHub Desktop.
Terrible depth-of-field effect for Processing.
void setup()
{
size (500, 500);
colorMode (RGB, 1);
frameRate (25);
}
final int LAYERS = 5;
final int LOOP_LENGTH = 100;
void draw()
{
background (1);
final int FRAME = frameCount % LOOP_LENGTH;
final float TIME = FRAME / float(LOOP_LENGTH);
final float FOCUS = (cos (TIME * TWO_PI) * 0.5 + 0.5) * (LAYERS - 1);
PGraphics pg = createGraphics (width, height);
final float RECT_INC = pg.width / (2.0 * (LAYERS + 2));
for (int i = 0; i != LAYERS; ++i)
{
pg.beginDraw();
pg.colorMode (RGB, 1);
pg.noFill();
pg.stroke(0);
pg.rect
( (i + 1) * RECT_INC
, (i + 1) * RECT_INC
, pg.width - (i + 1) * RECT_INC * 2
, pg.height - (i + 1) * RECT_INC * 2
);
pg.filter (BLUR, abs (i - FOCUS));
pg.endDraw();
image (pg, 0, 0);
}
saveFrame ("###-blur.png");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment