/* A demo of opening files for writing rib invoking another exe M. Kesson 4.8.03 */ #include #include #include float randBetween(float min, float max); int main(void) { FILE *fp; float xyz[3]; int n; /* one character at a time */ fp = fopen("disk_archive.rib", "w"); if(fp == NULL) return 1; /* generate random points */ for(n = 0; n < 1000; n++) { xyz[0] = randBetween(-1, 1); /* x */ xyz[1] = 0; /* y */ xyz[2] = randBetween(-1, 1); /* z */ fprintf(fp, "TransformBegin\n"); fprintf(fp, "Translate %f %f %f\n", xyz[0], xyz[1], xyz[2]); xyz[0] = randBetween(0, 1); /* r */ xyz[1] = randBetween(0, 1); /* g */ xyz[2] = randBetween(0, 1); /* b */ fprintf(fp, "Color %f %f %f\n", xyz[0], xyz[1], xyz[2]); fprintf(fp, "Sphere 0.02 -0.02 0.02 360\n"); fprintf(fp, "TransformEnd\n"); } fclose(fp); return 0; } float randBetween(float min, float max) { return ((float)rand()/RAND_MAX) * (max - min) + min; }