Last active
May 22, 2016 05:17
-
-
Save kitschpatrol/4e2a6f416021ee1a16d7cbcdad8f9f58 to your computer and use it in GitHub Desktop.
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
int frame = 0; | |
int wallOffset = 0; | |
final int windowWidth = 1; | |
final int wallWidth = 4; | |
boolean isDrawWallEnabled = false; | |
boolean isWallAnimated = true; | |
PImage pattern; | |
void setup() { | |
size(500, 500); | |
frameRate(60); | |
// use pgraphics instead | |
// create and set the patter accumulator to white | |
pattern = createImage(width, height, RGB); | |
for (int i = 0; i < pattern.pixels.length; i++) { | |
pattern.pixels[i] = color(255); | |
} | |
pattern.updatePixels(); | |
} | |
void draw() { | |
background(255); | |
// sample | |
if (frame < width) { | |
// draw a frame of animation | |
fill(0); | |
noStroke(); | |
ellipse((float)frame * 3, (float)frame * 3, 50.0, 50.0); | |
// copy relevant slices of frame into pattern accumulation image | |
int windowOffset = frameCount % (wallWidth + windowWidth); | |
for (int x = windowOffset; x < width; x += wallWidth + windowWidth) { | |
for (int i = 0; i < windowWidth; i++) { | |
int windowX = x + i; | |
for (int y = 0; y < height; y++) { | |
// dumb darkest blend | |
color baseColor = pattern.get(windowX, y); | |
color newColor = get(windowX, y); | |
pattern.set(windowX, y, color(min(red(newColor), red(baseColor)), min(green(newColor), green(baseColor)), min(blue(newColor), blue(baseColor)))); | |
} | |
} | |
} | |
} else { | |
// draw the image when we are done sampling | |
image(pattern, 0, 0); | |
} | |
// decoder | |
if (isDrawWallEnabled) { | |
for (int i = (wallOffset % wallWidth) - wallOffset; i < width; i += wallWidth + windowWidth) { | |
fill(0); | |
noStroke(); | |
rect(i, 0, wallWidth, height); | |
} | |
} | |
if (isWallAnimated) { | |
wallOffset += windowWidth; | |
} | |
frame += wallWidth; | |
} | |
void keyPressed() { | |
if (keyCode == RIGHT) { | |
wallOffset++; | |
} else if (keyCode == LEFT) { | |
wallOffset--; | |
} else if (key == ' ') { | |
isDrawWallEnabled = !isDrawWallEnabled; | |
} else if (key == 'a') { | |
isWallAnimated = !isWallAnimated; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment