/*  copyright 1997, zap technologies  */

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>

char *strhex(unsigned long int v, int w, char *s);

main() {
  int b,g,r;
  time_t tm;
  char bg[8], tx[8], tl[8], vl[8];

  time(&tm);
  srand(tm);
  b = rand() & 0xFF; g = rand() & 0xFF; r = rand() & 0xFF;
  strhex(r,2,bg); strhex(g,2,&bg[2]); strhex(b,2,&bg[4]);
  strhex(~r,2,tx); strhex(~g,2,&tx[2]); strhex(~b,2,&tx[4]);
  b = b << 2; g = g << 2; r = r << 2;
  strhex(~r,2,vl); strhex(~g,2,&vl[2]); strhex(~b,2,&vl[4]);

  printf("Content-type: model/vrml\n\n");
  printf("#VRML V2.0 utf8\n");
  printf("# copyright 1997, zap technologies\n");
  printf("# http://www.zaptech.comn\n\n");

  if (rand() & 1) {
    printf("Background {\n");
    printf("  skyColor [%7.3f %7.3f %7.3f]\n",
      (float) (rand() & 0xFF) / 255.0,
      (float) (rand() & 0xFF) / 255.0,
      (float) (rand() & 0xFF) / 255.0);
    printf("  }\n");
    }

  printf("\nShape {\n");
  printf("  appearance Appearance {\n");
  printf("    material Material { }\n");
  printf("    }\n");
  printf("  geometry Cylinder {\n");
  printf("    radius %d\n", (rand() & 3) + (rand() & 3) + 2);
  printf("    height %d\n", (rand() & 7) + (rand() & 3) + 2);
  printf("    }\n");
  printf("  }\n");

  if (rand() & 1) {
    printf("\nViewpoint {\n");
    printf("  position %7.3f %7.3f %7.3f\n", 0.0, 0.0,
      (float) ((rand() & 3) + (rand() & 3) + 2) * 10.0);
    printf("  }\n\n");
    }
  }


char *strhex(unsigned long int v, int w, char *s) {
  int i;

  s[w] = 0;
  while (w--) {
    i = v & 0xF;
    if (i < 10)
      s[w] = '0' + i;
    else
      s[w] = 'A' - 10 + i;
    v = v >> 4;
    }
  return(s);
  }

