Skip to content

Instantly share code, notes, and snippets.

@andrusenn
Last active May 6, 2019 23:53
Show Gist options
  • Save andrusenn/b630fb4bb80c7fabe3c8842a94bbb491 to your computer and use it in GitHub Desktop.
Save andrusenn/b630fb4bb80c7fabe3c8842a94bbb491 to your computer and use it in GitHub Desktop.
Cut & noise function
/**
* Fragmenta la imagen y la desplaza
* Fragment the image and displace it
*/
function CutNoise() {
let arg = arguments
let mx = mouseX
let my = mouseY
if (arg.length > 0) {
mx = arg[0]
my = arg[1]
}
let r = 2;
push()
loadPixels()
for (let x = 0; x < width; x += r) {
for (let y = 0; y < height; y += r) {
if (dist(mx, my, x, y) < 2) {
// Tamaños de los cortes / Cut sizes --------------------------------
let r1 = random(5, 200);
let r2 = random(5, 200);
// Nueva posicion de los cortes / new position ----------------------
let nxi = map(noise(x * 0.02, y * 0.02), 0, 1, -20, 20) * cos(x * 0.1);
let nyi = map(noise(x * 0.02, y * 0.02), 0, 1, -20, 20) * sin(x * 0.1);
// Cortes / cuts ----------------------------------------------------
let i1 = get(x - int(r1 / 2), y - int(r2 / 2), int(r1), int(r2));
// ------------------------------------------------------------------
rectMode(CENTER);
imageMode(CENTER);
noStroke();
//Sombra / Shadow
fill(0, 20);
rect((x + nxi) + 10, (y + nyi) + 10, i1.width, i1.height);
// Image
image(i1, int(x + nxi), int(y + nyi));
// Marco / Frame
strokeWeight(0.4);
let col = get(x, y)[0]
if (brightness(col) > 50) {
stroke(0, 100);
} else {
stroke(255, 100);
}
noFill();
// Marco
rect((x + nxi), (y + nyi), i1.width, i1.height);
}
}
}
pop()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment