makeInverseCenter( FILE *image, int nrows, int ncols )
{
int r, c, level ; /* row and col of current pixel */
int rc, cc ; /* row and col of center of image */
int rd, cd ; /* row and col difference from center */
double length, dist ;
rc = nrows/2;
cc = ncols/2;
/* determine the half diagonal length */
length = sqrt( (double)(nrows*nrows + ncols*ncols) ) / 2.0 ;
/* write out the pixel data */
for ( r=0; r<nrows; r++ )
{
rd = r - rc;
for ( c=0; c<ncols; c++ )
{
cd = c - cc;
dist = sqrt( (double)(rd*rd + cd*cd) );
level = (int)(255*(1.0-dist/length));
fputc( level, image );
}
}
}
Comments: Calculating the gray level involves more tricks than in the previous program.