image distortion question
              in 
             Programming Questions 
              •  
              1 years ago    
            
 
           
             Hi people,
            
             
            
            
                 
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
 
            
           
                 For now, my goal is to be able to distort an image as if it was a badly tuned old TV. (remember? when the image was distorting from left to right as if attacked by a wave).
            
            
                 I have tried a little sketch where i have loaded a 100*100 image, tried to select a piece of it thanks to a for structure and an array and then move it too the right when a key is pressed.
            
            
                 And so far it is not working, yay! 
            
            
                 Can someone has the kindness to correct this sketch? I am a bit locked here and i would like to move on with the exploring.
            
            
                Thanks a thousand!
            
            
             the sketch:
            
            
             PImage img;
            
            
             int[] imagePiece;
            
            
             void setup() {
            
            
               size(100, 100);
            
            
               noStroke();
            
            
               img = loadImage("chambre try out.jpg");
            
            
               imagePiece = new int[img.width*img.height];
            
            
               for(int x = 0; x < img.width; x++) {
            
            
                 for(int y = 20; y < 30; y++) {
            
            
                   imagePiece[x*img.width + y] = img.get(x, y);
            
            
                 }
            
            
               }  
            
            
             }
            
            
             void draw() {
            
            
               background(0);
            
            
               image(img, 0, 0);
            
            
               for(int x = 0; x < img.width; x++) {
            
            
                 for(int y = 20; y < 30; y++) {            
            
            
                   if(keyPressed == true ) {
            
            
                    x += 20;
            
            
                   }
            
            
                 }
            
            
               }
            
            
             } 
            
 
            
              
              1  
            
 
            
 
 
           
 
            