/* p12.c */ /* Construct a solid color image of the specified color */ /* Command line arguments: */ /* width in pixels */ /* height in pixels */ /* red value */ /* green value */ /* blue value */ #include #include unsigned char image[300 * 200]; #if 0 unsigned char pix_value( int r, int c) { unsigned char pix; pix = 28 + (r + c) % 200; return(pix); } unsigned char pix_value( int r, int c) { unsigned char pix; pix = (((r - 100) * (r - 100) + (c - 150) * (c - 150)) / 50) % 255; return(pix); } #endif unsigned char pix_value( int r, int c) { unsigned char pix; pix = (r * r + c * c) % 255; return(pix); } int main( int argc, char **argv) { int ndx = 0; int row; int col; while (ndx < (300 * 200)) { row = ndx / 300; col = ndx % 300; image[ndx] = pix_value(row, col); ndx = ndx + 1; } fprintf(stdout, "P5\n"); fprintf(stdout, "%d %d 255\n", 300, 200); fwrite(image, 300, 200, stdout); return(0); }