Funhouse Mirror


  // Funhouse Mirror - Jim Bumgardner
  //
  // @pjs preload="/assets/headshot_2.jpg"
  
  PImage  sourceImage;
  
  void setup()
  {
    size(500,640);
    sourceImage = loadImage("/assets/headshot_2.jpg");
    loadPixels();
  }
  
  void draw()
  {
    for (int y = 0; y < height; ++y) {
      for (int x = 0; x < width; ++x) {
        float dMouse = dist(mouseX, mouseY, x, y );
  
        float r = map(dMouse,0,width/2,1,0);
        r = constrain(r,0,1);
        int sx = int(lerp(x,mouseX,r));
        int sy = int(lerp(y,mouseY,r));
  
        pixels[y*width+x] = sourceImage.pixels[sy*width+sx];
      }
    }
    updatePixels();
  }