xxxxxxxxxx
48
var source;
var destination;
function preload(){
source = loadImage("frog.jpg");
}
function setup() {
createCanvas(500, 500);
smooth();
destination = createImage(source.width, source.height);
background(0);
}
function draw() {
source.loadPixels();
destination.loadPixels();
var fuzz = 8;
for (var x = 0; x < source.width; x++) {
for (var y = 0; y < source.height; y++) {
var d = int(dist(width/2, height/2, mouseX, mouseY));
var maxDist = int(dist(0, 0, width/2, height/2));
var factor = map(d, 0, maxDist, 0, fuzz+(fuzz/4));
var loc = x + y * source.width;
if ( 0 < x && x < fuzz + ( fuzz/2)) {
var loc2 = (x + int(random(0, factor)) + y * source.width);
destination.pixels[loc] = source.pixels[loc2];
} else if ( source.width - fuzz - (fuzz/2) < x && x < source.width) {
var loc3 = (x + int(random(-factor, 0)) + y * source.width);
destination.pixels[loc] = source.pixels[loc3];
} else if ( 0 + fuzz < x && x < source.width - fuzz) {
var loc4 = (x + int(random(-factor, factor)) + y * source.width);
destination.pixels[loc] = source.pixels[loc4];
}
}
}
destination.updatePixels();
imageMode(CENTER);
image(destination, width/2, height/2);
}