home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / graphtal / examples / bncngbll < prev    next >
Text File  |  1992-11-02  |  3KB  |  107 lines

  1. #!/bin/sh
  2. #
  3. # Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
  4. # All rights reserved.
  5. #
  6. # This software may be freely copied, modified, and redistributed
  7. # provided that this copyright notice is preserved on all copies.
  8. #
  9. # You may not distribute this software, in whole or in part, as part of
  10. # any commercial product without the express consent of the authors.
  11. #
  12. # There is no warranty or other guarantee of fitness of this software
  13. # for any purpose.  It is provided solely "as is".
  14. #
  15. #
  16. # Generate bouncing ball animation (uses balls.anim.lsys).
  17. #
  18. # usage: bouncingball [-R resX resY] [-O outfile] 
  19. #                     [-d rayshade|flat] numberOfFrames
  20. #
  21.  
  22. nawk '
  23. BEGIN { 
  24.   resX = 150; 
  25.   resY = 150;
  26.   outfile = "bounce.rle";
  27.   renderer = "flat";
  28.  
  29.   if (ARGC <= 1) 
  30.     usage(); 
  31.  
  32.   #
  33.   # Parse command line options.
  34.   #
  35.   while (++i < ARGC-1) { 
  36.     if (ARGV[i] ~ /^-R$/) { 
  37.       if (((ARGC-i) > 3) && 
  38.       ((ARGV[i+1] ~ /^[0-9]+$/) && (ARGV[i+2] ~ /^[0-9]+$/))) { 
  39.     resX = ARGV[++i]; 
  40.     resY = ARGV[++i];
  41.       }
  42.       else
  43.     usage();
  44.     }
  45.     else if (ARGV[i] ~ /^-O$/) {
  46.       if ((ARGC-i) > 2)
  47.         outfile = ARGV[++i];
  48.       else
  49.         usage();
  50.     }
  51.     else if (ARGV[i] ~ /^-d$/) {
  52.       if ((ARGC-i) > 2 && (ARGV[i+1] ~ /^(rayshade|flat)$/))
  53.         renderer = ARGV[++i];
  54.       else
  55.         usage();
  56.     }
  57.     else if (i < ARGC-1)
  58.       usage();
  59.     else 
  60.       break;
  61.   }
  62.  
  63.   #
  64.   # Get number of frames to be rendered.
  65.   #
  66.   if ((i >= ARGC) || (ARGV[i] !~ /^[0-9]+$/))
  67.     usage();
  68.   else
  69.     numberOfFrames = ARGV[i];
  70.  
  71.   #
  72.   # Render images...
  73.   #
  74.   for (i=0; i<numberOfFrames; i++) {
  75.     if (renderer == "flat")
  76.       cmd = "graphtal -q -R " resX " " resY " -Diter=" i \
  77.             " -d flat balls.anim.lsys | ppmtorle | rleflip -v" \
  78.         " > _frame" i ".rle";
  79.     else
  80.       cmd = "graphtal -q -R " resX " " resY " -Diter=" i \
  81.             " -d rayshade ball.lsys;" \
  82.             "rayshade default.ray > _frame" i ".rle";
  83.  
  84.     print cmd; 
  85.     if (system(cmd)) exit(1);
  86.     if (i == 0) {
  87.       print "mv _frame" i ".rle " outfile;
  88.       system("mv _frame" i ".rle " outfile);
  89.     }
  90.     else {
  91.       print "rlecat -o tmp.rle " outfile " _frame" i ".rle";
  92.       system ("rlecat -o tmp.rle " outfile " _frame" i ".rle");
  93.       print "mv tmp.rle " outfile;
  94.       system ("mv tmp.rle " outfile);
  95.       system("rm _frame" i ".rle");
  96.     }
  97.   }
  98. }
  99.  
  100. function usage()
  101. {
  102.   print "usage: bouncingball [-R resX resY] [-O outfile]";
  103.   print "                    [-d rayshade|flat]  numberOfFrames\n";
  104.   exit(1);
  105. }
  106. ' $*
  107.