line experiment
More pixel shifting experiments…
Processing Code:
//PixelShifting by Phillip Stearns 2014
PImage sourceImg;
int iteration;
void setup(){
iteration=0;
sourceImg = loadImage("shift.jpg");
size(sourceImg.width, sourceImg.height);
}
void draw(){
int yoffset = int(random(height));
int xoffset= int(random(width));
int randomRows= int(random(height)) - yoffset;
int randomColumns=int(random(width)) - xoffset;
for(int i = 0 ; i < randomRows ; i++){
shiftRow(sourceImg, i+yoffset, 15);
}
for(int j = 0 ; j < randomColumns ; j++){
shiftColumn(sourceImg, j+xoffset, 15);
}
image(sourceImg, 0, 0);
sourceImg.save("shifted_" +nf(iteration, 3)+ ".png");
iteration++;
}
void shiftRow(PImage image, int row, int shift){
int[] buffer = new int[image.width];
if (row < 0 || row >= height){
println("Row value is out of range.");
} else{
for(int i = 0 ; i < image.width ; i++){
buffer[(i+shift) % (image.width)] = image.pixels[row*image.width+i];
}
for(int j = 0 ; j < image.width ; j++){
sourceImg.pixels[row*image.width+j] = buffer[j];
}
}
sourceImg.updatePixels();
}
void shiftColumn(PImage image, int column, int shift){
int[] buffer = new int[image.height];
if(column < 0 || column >= width){
println("Column value is out of range.");
}else{
for(int i = 0 ; i < image.height ; i++){
buffer[(i+shift) % (image.height)] = image.pixels[i*image.width+column];
}
for(int j = 0 ; j < image.height ; j++){
sourceImg.pixels[j*image.width+column] = buffer[j];
}
}
sourceImg.updatePixels();
}


