/* Circular moire pattern generator. ./circular_moire > output.pgm */ #include #include #include #include #ifdef _WIN32 #include #include #endif #define CIRCLE_COUNT 3 int main(int argc, char **argv) { int width, height, x, y, i; double cx[CIRCLE_COUNT], cy[CIRCLE_COUNT], scale[CIRCLE_COUNT], a; if( argc != 3 || (width = atoi(argv[1])) <= 0 || (height = atoi(argv[2])) <= 0 ) { return printf("%s \n", *argv); } if( width >= 0x8000 || height >= 0x8000 ) return !puts("Output size too large."); #ifdef _WIN32 setmode(STDOUT_FILENO, O_BINARY); #endif srand(time(NULL)); for(i = 0; i < CIRCLE_COUNT; i++) { cx[i] = (double)rand() / RAND_MAX * width; cy[i] = (double)rand() / RAND_MAX * height; scale[i] = ((double)rand() / RAND_MAX * 30.0 + 6.0) / (width < height ? width : height); } printf("P5\n%d %d\n255\n", width, height); for(y = 0; y < height; y++) { for(x = 0; x < width; x++) { a = 0; for(i = 0; i < CIRCLE_COUNT; i++) a += sin(hypot(x - cx[i], y - cy[i]) * scale[i]) + 1.0; fputc((int)(a * 255.0 / (2.0 * CIRCLE_COUNT)), stdout); } } return 0; }