I68 Answer ― Two Color Gradient


Here is the relevant part of the program. Each pixel of the image is visited in raster order, as before. Now the amount of red for a pixel is a mix of the amount of red in the left edge and the amount of red in the right edge. Green and blue are similar.

  /* write out the pixel data */
  for ( r=0; r<nrows; r++ )
    for ( c=0; c<ncols; c++ )
    {
      red = redL + ((redR-redL)*c)/(ncols-1);
      grn = grnL + ((grnR-grnL)*c)/(ncols-1);
      blu = bluL + ((bluR-bluL)*c)/(ncols-1);
      fputc( red, image );  fputc( grn, image );  fputc( blu, image );
    }
linear function graph