Here is the relevant part of the solution:
for ( r=0; r<nrows; r++ )
for ( c=0; c<ncols; c++ )
{
dist = sqrt( (r-cntR)*(r-cntR) + (c-cntC)*(c-cntC)) ;
thetaCC = atan2( (c-cntC), (r-cntR) );
radians = 2*M_PI*(dist/radius) ;
red = 125 + 125*cos( radians + thetaCC*redCycles );
grn = 125 + 125*cos( radians + thetaCC*grnCycles );
blu = 125 + 125*cos( radians + thetaCC*bluCycles );
fputc( red, image ); fputc( grn, image ); fputc( blu, image );
}
Comments: Most of the work in this program is in rearanging the calculation for the color values.