home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 August - Disc 1 / PCNET_CD_2006_08_1.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / bin / ppmrainbow < prev    next >
Encoding:
Text File  |  2004-06-14  |  1.4 KB  |  68 lines

  1. #!/usr/bin/perl -wl
  2. use strict;
  3. use Getopt::Long;
  4.  
  5. my ($FALSE, $TRUE) = (0,1);
  6.  
  7. (my $myname = $0) =~ s#\A.*/##;
  8.  
  9. my ($Twid, $Thgt, $tmpdir, $verbose);
  10.  
  11. # set defaults
  12. $Twid = 600;
  13. $Thgt = 8;
  14. $tmpdir = $ENV{"TMPDIR"} || "/tmp";
  15. $verbose = $FALSE;
  16.  
  17. (my $usage = <<EOD ) =~ s/^\t//mg;
  18.     Usage: $myname [ options ] color ...
  19.  
  20.     Creates a color bar with smoothly changing colors.
  21.  
  22.     Options:
  23.         -width    width of the color bar (default $Twid)
  24.         -height    height of the color bar (default $Thgt)
  25.         -tmpdir    working directory (default envar TMPDIR or \/tmp)
  26.         -verbose    echo shell commands to STDERR
  27. EOD
  28.  
  29. GetOptions("width=i" => \$Twid,
  30.            "height=i" => \$Thgt,
  31.            "tmpdir=s" => \$tmpdir,
  32.            "verbose!" => \$verbose);
  33.  
  34. die "invalid width and/or height\n" unless $Twid >= 1 && $Thgt >= 1;
  35.  
  36. my $verboseCommand = $verbose ? "set -x;" : "";
  37.  
  38. if (@ARGV < 1) {
  39.     die("You must specify at least one color as an argument");
  40. }
  41.  
  42. my $numcol = scalar @ARGV;
  43. push @ARGV, $ARGV[0];
  44.  
  45. my $tmpprefix = $tmpdir . "/$myname.$$.";
  46. my @outlist = ();
  47. my $n = 0;
  48.  
  49. while (@ARGV >= 2) {
  50.     push @outlist, my $outfile = sprintf "%s%03u.ppm", $tmpprefix, $n;
  51.     my $w = int(($Twid-1)/$numcol)+1;
  52.     0 == system qq{$verboseCommand pgmramp -lr $w $Thgt | pgmtoppm "$ARGV[0]-$ARGV[1]" >$outfile}
  53.     or exit 1;
  54.     $Twid -= $w;
  55.     $numcol--;
  56.     $n++;
  57.     shift @ARGV;
  58. }
  59.  
  60. 0 == system qq{$verboseCommand pnmcat -lr @outlist}
  61.     or exit 1;
  62.  
  63. exit 0;
  64.  
  65. END {
  66.     unlink @outlist if @outlist;
  67. }
  68.