Last active
July 17, 2017 01:12
-
-
Save veev/2a73ea14b95be7fca206da86b817681a 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
// I made this when I was experimenting with Moiré patterns and | |
// trying to generate ways to print out designs that would animate | |
// if you put the right interference line pattern over it and moved it across. | |
// Much like the book by Takahiro Kurashima, Poemotion: http://andpens.com/tag/moire-pattern/ | |
int frame = 0; | |
int wallOffset = 0; | |
final int windowWidth = 1; | |
final int wallWidth = 4; | |
boolean isDrawWallEnabled = false; | |
boolean isWallAnimated = true; | |
PImage pattern; | |
float r = 40.0; | |
float theta = 0.0; | |
float thetaInc = 0.05; | |
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); | |
println(frame); | |
// sample | |
if (frame < width) { | |
// draw a frame of animation | |
pushMatrix(); | |
translate(width/2, height/2); | |
for (int c = 1; c < 10; c++) { | |
float xPos = (r*c) * cos(theta); | |
float yPos = (r*c) * sin(theta); | |
strokeWeight(2); | |
stroke(0); | |
noFill(); | |
ellipse(xPos, yPos, 2 * c, 2 * c); | |
} | |
popMatrix(); | |
theta += thetaInc; | |
// 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