I24 Answer — Random Circles


int main ( int argc, char* argv[] )
{
  image img ;
  int nrows, ncols, bgvalue, fgvalue;
  int radius, howmany ;
  int j, r, c;

  if ( argc != 8)
  {
    printf("manyCircles fileName nrows ncols bkground");
    printf(" fground radius howmany\n");
    return EXIT_SUCCESS;
  }

  nrows   = atoi( argv[2] );
  ncols   = atoi( argv[3] );
  bgvalue = atoi( argv[4] );
  fgvalue = atoi( argv[5] );
  radius  = atoi( argv[6] );
  howmany = atoi( argv[7] );

  newImage( &img, nrows, ncols );

  clearImage( img, bgvalue );
  srand( time(NULL) );

  for ( j=0; j < howmany; j++ )
  {
    r = rand()%nrows;
    c = rand()%ncols;
    drawCircle( img, r, c, radius, fgvalue );
  }

  writePGMimage( img, argv[1]);
  freeImage( &img );
  
}

Comments:


back