#include #include #define S 100 static void putit(double d) { if (d < 0) d = 0; else if (d > 255) d = 255; printf("%d\n",(int)d); } int main(void); int main(void) { int x; int y; double rho; double phi; double r; double g; double b; printf("P3\n%d %d\n255\n",S,S); for (y=0;y (S-1)/2.0) { r = 0; g = 0; b = 0; } else { if (phi < 0) phi += 360; if (phi >= 360) phi -= 360; r = (phi < 120) ? (((phi ) * 256) / 120) : (phi < 240) ? (((240 - phi) * 256) / 120) : 0; g = (phi < 120) ? 0 : (phi < 240) ? (((phi - 120) * 256) / 120) : (((360 - phi) * 256) / 120); b = (phi < 120) ? (((120 - phi) * 256) / 120) : (phi < 240) ? 0 : (((phi - 240) * 256) / 120); } putit(127.5+((r-127.5)*(rho/((S-1)/2.0)))); putit(127.5+((g-127.5)*(rho/((S-1)/2.0)))); putit(127.5+((b-127.5)*(rho/((S-1)/2.0)))); } } return(0); }