make_tartan_files.anubis 2.24 KB

                              A demo for the ``Tartan'' generator. 

   
   Author: Alain Prouté

   Compile this file and execute:
   
   anbexec make_tartan_files 10
   
   to generate 10 tartan images. 
  
   
   --- That's all for the public part ! --------------------------------------------------
   
   

read tools/basis.anubis   
read tartan_generator.anubis
   
   
   
define One 
   make_files
     (
        Int w, 
        Int h, 
        Int n
     ) =
   if n =< 0 then unique else
   if unow is utime(sec,msec) then 
     with im = make_tartan_image(w,h), 
       if write_image_to_JPEG_file(to_JPEG(im),"tartan_"+to_decimal(sec)+"_"+to_decimal(msec)+".jpg",95) is 
         {
           cannot_create_file  then print("Cannot create JPEG file.\n\n"), 
           compression_error   then print("JPEG compression error.\n\n"),
           ok  then print("JPEG file created ("+to_decimal(n)+")\n"); 
                    make_files(w,h,n-1)
         }. 
   

define One
   usage = 
   print("Usage: anbexec make_tartan_files <width> <height> <how many>\n"+
                      "   where <width> and <height> is the size of the image,\n"+
                      "   and where <how many> is the number of files to generate.\n\n").
   
global define One
   make_tartan_files
     (
       List(String) args
     ) =   
   if args is 
     {
       [ ] then usage, 
       [h1 . t1] then if decimal_scan(h1) is 
         {
           failure then print("Argument <width> has not been recognized as an integer.\n\n"),
           success(w) then if t1 is
             {
               [ ] then usage, 
               [h2 . t2] then if decimal_scan(h2) is
                 {
                   failure then print("Argument <height> has not been recognized as an integer.\n\n"),
                   success(h) then if t2 is 
                     {
                       [ ] then usage, 
                       [h3 . _] then if decimal_scan(h3) is
                         {
                           failure then print("Argument <how many> has not been recognized as an integer.\n\n"),
                           success(n) then
                             make_files(w,h,n)
                         }
                     }
                }
             }
         }
     }.