#!/usr/bin/perl

$|=1;
my $X = $ENV{MCMAHON_SIZE} || 50;

my %cmap = ('red' => "\xff\x00\x00",
            'blue' => "\x00\x00\xff",
            'blu' => "\x00\x00\xff",
            'green' => "\x00\xff\x00",
            'grn' => "\x00\xff\x00",
            'black' => "\x00\x00\x00",
            'blk' => "\x00\x00\x00",
            'white' => "\xff\xff\xff",
            'wht' => "\xff\xff\xff",
            'yellow' => "\xff\xff\x00",
            'yel' => "\xff\xff\x00",
            'purple' => "\x88\x00\x88",
            'pur' => "\x88\x00\x88",
            'pink' => "\xff\x88\x88",
            'orange' => "\xff\x88\x00",
            'ora' => "\xff\x88\x00",
            'magenta' => "\xff\x00\xff",
            'mag' => "\xff\x00\xff",
            'brown' => "\x88\x44\x00",
            'brn' => "\x88\x44\x00",
           );

@ARGV == 4 or usage();  # Top, left, right, bot
for (@ARGV) { 
  $_ = $cmap{$_} || die "Unknown color '$_'\n";
}
my ($T, $L, $R, $B) = @ARGV;

print "P6\n$X $X\n255\n";

for my $r (0 .. $X-1) {
  my $topq = $r < $X/2;
  my $M = $topq ? $T : $B;
  my $midwid = $topq ? $X - $r * 2 : $r * 2 - $X + 2;
  my $s = int(($X - $midwid) / 2);
  die "midwid = $midwid; s = $s\n" unless $midwid + $s + $s == $X;
  my $line = $L x $s . $M x $midwid . $R x $s;
#  my $ll = length($line);
#  die "line length $ll\n" unless $ll = $X * 3;
  print $line;
#  $total += $ll;
}
# warn "total == $total \n";
