Skip to content

Instantly share code, notes, and snippets.

@volfegan
Last active May 9, 2022 02:42
Show Gist options
  • Save volfegan/56abfcdda38fc97f0471cf0d1dbcb68b to your computer and use it in GitHub Desktop.
Save volfegan/56abfcdda38fc97f0471cf0d1dbcb68b to your computer and use it in GitHub Desktop.
Glitch effect for images warping from one side of the screen to another
//reference https://timrodenbroeker.de/processing-tutorial-kinetic-typography-1/
//https://github.com/timrodenbroeker/tutorials/blob/master/2019/002_Processing_Kinetic_Typography/TUTORIAL/
//https://twitter.com/inaba_darkfox/status/1523319283157467136
PImage img;
void settings() {
img=loadImage("cat.jpg");
size(img.width, img.height, P2D);
println("w="+img.width+", h="+img.height);
}
void draw() {
image(img,0,0);
int tilesX = 40;//original value 10
int tilesY = 40;//original value 10
int tileW = int(width/tilesX);
int tileH = int(height/tilesY);
for (int y = 0; y <= tilesY+1; y++) {
for (int x = 0; x <= tilesX+1; x++) {
int wave, waveHard, warp, warpSimple, warpQuantum, glitch;
int sx, sy, sw, sh, dx, dy, dw, dh;
wave = int(sin(frameCount * 0.05 + (x + y) * 0.07) * 100);
waveHard = int(sin(frameCount * 0.05 + (x * y) * 0.07) * 100);
warpSimple = int(tan((frameCount + (x+y)) * 0.01) * 100);
warp = int(tan(pow((((frameCount*10 + ((x*13+y*7)*5)%53)%width*1.5)-width*.8)/width*1.2, 5)) * width);
warpQuantum = int(tan((frameCount + (x^y)) * 0.01) * 50);//(x|y) or (x^y)|(x&y) for a different effect
glitch = warpQuantum%(waveHard==0 ? 1 : waveHard);
// SOURCE
//sx = x*tileW + wave;
//sx = x*tileW + waveHard;
//sx = x*tileW - warpSimple;
sx = x*tileW - warp;
//sx = x*tileW - warpQuantum;
//sx = x*tileW - glitch;
//sx = x*tileW + glitch - warpQuantum; //Digital quantum tunnelling cat
sy = y*tileH;
sw = tileW;
sh = tileH;
// DESTINATION
dx = x*tileW;
dy = y*tileH;
dw = tileW;
dh = tileH;
copy(img, sx, sy, sw, sh, dx, dy, dw, dh);
}
}
//saveFrame("frame_######.png");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment