
int IMGHEIGHT;
int IMGWIDTH;
int diff;
int steps;
PImage[] images = new PImage[2];
float[] weight=new float [2];

void setup() 
{

  IMGHEIGHT=600;
  IMGWIDTH=600;
  
  frameRate(100);
  images[0] = loadImage("1mosaic1.jpg");
  images[1] = loadImage("1.jpg");  
steps=50;
   weight[0]=0;
  weight[1]=steps;

diff=1;
  size(IMGWIDTH,IMGHEIGHT);
  //noLoop();
}
void draw()
{
   weight[0]=weight[0]+diff;
   if (weight[0]>steps){
    diff=diff*-1;
   }
   if (weight[0]<0){
     diff=diff*-1;
   }
   weight[1]=steps-weight[0];
   

 
  int cols;
  int rows;

  int sub;
  int i;
  float r;
  float g;
  float b;

  float sumR;
  float sumG;
  float sumB;
  
  float totalWeight;

   loadPixels();
   
   for (rows=0;rows<IMGHEIGHT;rows++){
      for (cols=0;cols<IMGWIDTH;cols++){
             
                   
                   sub=(rows*IMGWIDTH) + cols;
                
                   totalWeight=0;
                   sumR=0;
                   sumG=0;
                   sumB=0;
                   for(i=0;i<images.length;i++){
                     r=red(images[i].pixels[sub])*weight[i];;
                     g=green(images[i].pixels[sub])*weight[i];;
                     b=blue(images[i].pixels[sub])*weight[i];;
                     sumR=sumR+r;
                     sumG=sumG+g;
                     sumB=sumB+b;
                     totalWeight=totalWeight+weight[i];
                   }

                
                   pixels[sub]=color(int(sumR/totalWeight),int(sumG/totalWeight),int(sumB/totalWeight) );
 
         
      }
 }


   updatePixels();

  //save("cleomosaic3.jpg
  
}
