Skip to content

Instantly share code, notes, and snippets.

@volfegan
Last active February 1, 2021 22:11
Show Gist options
  • Save volfegan/36de7415d4c862ba82b67f936ac04cf8 to your computer and use it in GitHub Desktop.
Save volfegan/36de7415d4c862ba82b67f936ac04cf8 to your computer and use it in GitHub Desktop.
Reflect an image into the 4 sides and flow it inward like a sinkhole
//https://www.youtube.com/watch?v=2nqFZ5QgCqw
PImage img;
int column=2, line=2, u=1, v=1, x, y, w, h; //To avoid edge cases in the pixel array: column=2, line=2
boolean rotating = true;
void keyPressed() {
if (key == 'r' || key == 'R') {
if (rotating) rotating = false;
else rotating = true;
}
}
void settings() {
img=loadImage("cat.jpg");
size(w=img.width, h=img.height);
}
void setup() {
clear();
}
void draw() {
if (rotating) {
translate(width/2, height/2);
rotate(frameCount*.000001);
translate(-width/2, -height/2);
}
loadPixels();
//scan a horizontal line from the image and place it into the up & bottom frame
y=0;
for (x=0; x<w; x++) pixels[y*w+x] = img.get(x, column);
y=h-1;
for (x=0; x<w; x++) pixels[y*w+x] = img.get(x, column);
//scan a vertical line from the image and place it into the frame left/right sides
x=0;
for (y=0; y<h; y++) pixels[y*w+x] = img.get(line, y);
x=w-1;
for (y=0; y<h; y++) pixels[y*w+x] = img.get(line, y);
updatePixels();
/*
//for weird clock rotation and fractal appearing in the corner
rotating = false;
translate(width/2,height/2);
rotate(frameCount*.001);
*/
//To avoid edge cases in the pixel array: column=2, line=2, column>h-2, line>w-2, column<1, line<1
column+=v;
if (column>h-2 || column<1) v*=-1;
line+=u;
if (line>w-2 || line<1) u*=-1;
/*
//randomize the choice of the scanned lines for some abstract art tunel
column=int(random(h-1));
line=int(random(w-1));
*/
copy(this.get(), 0, 0, w, h, 1, 1, w-2, h-2);
//saveFrame("frame_######.png");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment