/* Linear moire pattern generator. ./linear_moire_bw > output.pgm This is same as linear_moire.c, except output is black and white instead of grayscale. */ #include #include #include #include #ifdef _WIN32 #include #include #endif #define PI 3.14159265358979323846264338327950288419716939937510 #define LINE_COUNT 3 int main(int argc, char **argv) { int width, height, x, y, i; double rx[LINE_COUNT], ry[LINE_COUNT], phase[LINE_COUNT], a, s; 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 < LINE_COUNT; i++) { s = ((double)rand() / RAND_MAX * 40.0 + 12.0) / (width < height ? width : height); a = (double)rand() / RAND_MAX * PI * 2.0; rx[i] = s * cos(a); ry[i] = s * sin(a); phase[i] = (double)rand() / RAND_MAX * PI * 2.0; } 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 < LINE_COUNT; i++) a += sin(x * rx[i] + y * ry[i] + phase[i]) + 1.0; fputc((double)rand() / RAND_MAX * 2.0 * LINE_COUNT > a ? 0 : 255, stdout); } } return 0; }