I19 Answer
#include <stdlib.h>
#include <stdio.h>
#include "basicImage.c"
int main ( int argc, char* argv[] )
{
image img ;
int r, c;
int nrows, ncols, below, above, radius ;
int rc, cc; /* coordinates of center */
if ( argc != 7)
{
printf("diagImage fileName nrows ncols below above radius\n");
system( "pause" );
return EXIT_SUCCESS;
}
nrows = atoi( argv[2] );
ncols = atoi( argv[3] );
below = atoi( argv[4] );
above = atoi( argv[5] );
radius= atoi( argv[6] );
if ( newImage( &img, nrows, ncols ) == NULL )
{
printf(">>error<< can't allocate memory\n");
return;
}
rc = nrows/2;
cc = ncols/2;
for ( r = 0; r<img.nrows; r++ )
for ( c = 0; c<img.ncols; c++ )
if ( r>c )
if ( (r-rc)*(r-rc) + (c-cc)*(c-cc) < radius*radius )
setPixel( img, r, c, below );
else
setPixel( img, r, c, above );
else
if ( (r-rc)*(r-rc) + (c-cc)*(c-cc) < radius*radius )
setPixel( img, r, c, above );
else
setPixel( img, r, c, below );
writePGMImage( img, argv[1]);
freeImage( &img );
}