Created
June 9, 2019 00:51
-
-
Save andrusenn/007ee41ae29c6d9cc771e89712466ead to your computer and use it in GitHub Desktop.
Remap pixels
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
/* | |
@param _x x position of center | |
@param _y y position of center | |
@param _d diemeter of circle | |
Andrés Senn | |
*/ | |
function RemapPixCircle(_x, _y, _d) { | |
loadPixels() | |
for (let x = _x-_d/2; x <_x+_d/2; x++) { | |
for (let y = _y-_d/2; y < _y+_d/2; y++) { | |
let dis = dist(x,y,_x,_y) | |
if (dis < _d/2) { | |
let idx = (x + y * width) * 4 | |
// Try changing noise size (0.001 / 0.0025) | |
let n = noise(x * 0.001, y * 0.0025, radians(frameCount)); | |
let nx = n * cos(x * 0.1 * n)*20; | |
let ny = n * sin(x * 0.1 * n)*20; | |
let nidx = (int(x + nx) + int(y + ny) * width) * 4 | |
let p1 = pixels[nidx] | |
let p2 = pixels[nidx + 1] | |
let p3 = pixels[nidx + 2] | |
let p4 = pixels[nidx + 3] | |
// try change with coeerct order or mix them | |
pixels[idx] = p2 | |
pixels[idx + 1] = p3 | |
pixels[idx + 2] = p1 | |
pixels[idx + 3] = p4 | |
} | |
} | |
} | |
updatePixels() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment