#!/usr/bin/perl

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

my %cmap = ('red' => "\xff\x00\x00",
            'R' => "\xff\x00\x00",
            'blue' => "\x00\x00\xff",
            'blu' => "\x00\x00\xff",
            'B' => "\x00\x00\xff",
            'green' => "\x00\xff\x00",
            'grn' => "\x00\xff\x00",
            'G' => "\x00\xff\x00",
            'black' => "\x00\x00\x00",
            'blk' => "\x00\x00\x00",
            'K' => "\x00\x00\x00",
            'white' => "\xff\xff\xff",
            'wht' => "\xff\xff\xff",
            'W' => "\xff\xff\xff",
            'yellow' => "\xff\xff\x00",
            'yel' => "\xff\xff\x00",
            'Y' => "\xff\xff\x00",
            'purple' => "\x88\x00\x88",
            'pur' => "\x88\x00\x88",
            'P' => "\x88\x00\x88",
            'pink' => "\xff\x88\x88",
            'orange' => "\xff\x88\x00",
            'ora' => "\xff\x88\x00",
            'O' => "\xff\x88\x00",
            'magenta' => "\xff\x00\xff",
            'mag' => "\xff\x00\xff",
            'M' => "\xff\x00\xff",
            'brown' => "\x88\x44\x00",
            'brn' => "\x88\x44\x00",
            'N' => "\x88\x44\x00",
           );

@ARGV == 9 or usage();  # Top, left, right, bot
for (@ARGV) { 
  $_ = $cmap{$_} || die "Unknown color '$_'\n";
}
print "P6\n$X $X\n255\n";

for my $r (0 .. $X-1) {
  my $row = int($r * 3 / $X);
  my @c = @ARGV[$row*3 .. $row*3+2];
  my $line = "";
  for (0..2) {
      $line .= $c[$_] x ($X/3);
  }
  print $line;
}
# warn "total == $total \n";
