/* Stripe pattern generator. ./stripes_generic > output.pgm This file implements stripe patterns by doing a coordinate transformation first. It's the same spirit as stripes.c, but more expensive. */ #include #include #include #include #ifdef _WIN32 #include #include #endif #define PI 3.14159265358979323846264338327950288419716939937510 int main(int argc, char **argv) { int width, height, x, y; double angle, scale, ratio, a, b, c, t; 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)); /* Generate transformation. */ angle = (double)rand() / RAND_MAX * 2.0 * PI; scale = (double)rand() / RAND_MAX * 0.09 + 0.01; a = cos(angle) * scale; b = sin(angle) * scale; c = (double)rand() / RAND_MAX; ratio = (double)rand() / RAND_MAX * 0.6 + 0.2; printf("P5\n%d %d\n255\n", width, height); for(y = 0; y < height; y++) { for(x = 0; x < width; x++) { t = a * x + b * y + c; fputc(t - floor(t) > ratio ? 255 : 0, stdout); } } return 0; }