I am trying to get the code below to distort an image. The distortion creates square bumps on the image surface.
The code below keeps giving me an out of bounds exeception. Hope someone could find the problem.
***********************************************************
PImage img;
PImage img_new;
int cellsize=2;
int cols, rows;
void setup(){
size(600,600);
img=loadImage("bcircle.jpg");
img_new=createImage(img.width,img.height,RGB);
cols = width/cellsize;
rows = height/cellsize;
}
void draw(){
img.resize(img.width,img.height);
img_new.loadPixels();
int shif=0;
for(int j=0; j<rows; j++){
for(int i=0; i<cols; i++){
int x=i*cellsize+cellsize/2;
int y=j*cellsize+cellsize/2;
int loc=x+width*y;
int left_loc=(x-cellsize)+width*y;
if(x>cellsize && x<width-cellsize && shif%2==0){
img_new.pixels[loc] = color (img.pixels[left_loc]);
}else{
img_new.pixels[loc] = color (img.pixels[loc]);
}
}
}
shif++;
img_new.updatePixels();
image(img_new,0,0);
}