[Home]ToothyWikiInternals/GoImages

ec2-3-80-4-76.compute-1.amazonaws.com | ToothyWiki | ToothyWikiInternals | RecentChanges | Login | Webcomic

If anyone cares, this is the script I used to generate the Go images for ToothyWikiInternals/GoMarkup. [IrfanView] can read the format this spews, and was used to batch convert it to GIF (a [cursory search] failed to come up with a copy of ppm2gif that I could use, although I found lots of manpages and scripts that used it. ppm2gif would be useful since it's yet another way I could generate large Go board images on the fly from the CGI script). Why did I do it like this? Because, um, I like pain.

#! /usr/bin/perl -w
use English;
use strict;

use FileHandle;

my %map = 
(
  '.' => "128 128 63\r\n",
  '*' => "0 0 0\r\n",
  'g' => "0 0 0\r\n",
  'd' => "128 128 128\r\n",
  'x' => "80 80 32\r\n",
  'o' => "172 172 96\r\n",
  'O' => "255 255 255\r\n"
);

my %cbmap =
(
  ''  => '.',
  'k' => '.',
  'b' => 'd',
  'w' => 'd'
);

my %cfmap =
(
  ''  => '*',
  'k' => '*',
  'b' => 'O',
  'w' => '*'
);

my %images =
( 
'd' => [
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '***************',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......'
],
'tl' => [
  '...............',
  '...............',
  '...............',
  '...............',
  '...............',
  '...............',
  '...............',
  '.......********',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......'
],
'tr' => [
  '...............',
  '...............',
  '...............',
  '...............',
  '...............',
  '...............',
  '...............',
  '********.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......'
],
'bl' => [
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......********',
  '...............',
  '...............',
  '...............',
  '...............',
  '...............',
  '...............',
  '...............'
],
'br' => [
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '********.......',
  '...............',
  '...............',
  '...............',
  '...............',
  '...............',
  '...............',
  '...............'
],
't' => [
  '...............',
  '...............',
  '...............',
  '...............',
  '...............',
  '...............',
  '...............',
  '***************',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......'
],
'b' => [
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '***************',
  '...............',
  '...............',
  '...............',
  '...............',
  '...............',
  '...............',
  '...............'
],
'l' => [
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......********',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......'
],
'r' => [
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '********.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......',
  '.......*.......'
]
);

my %counters = 
(
  '' => [
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               '
],
  'k' => [
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '       g       ',
  '      ggg      ',
  '     ggggg     ',
  '      ggg      ',
  '       g       ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               '
],
  'b' => [
  '               ',
  '       x       ',
  '     xgggx     ',
  '   xgggggggx   ',
  '   ggggggggg   ',
  '  xgggggggggx  ',
  '  ggggggggggg  ',
  ' xgggggggggggx ',
  '  ggggggggggg  ',
  '  xgggggggggx  ',
  '   ggggggggg   ',
  '   xgggggggx   ',
  '     xgggx     ',
  '       x       ',
  '               '
],
  'w' => [
  '               ',
  '       o       ',
  '     oOOOo     ',
  '   oOOOOOOOo   ',
  '   OOOOOOOOO   ',
  '  oOOOOOOOOOo  ',
  '  OOOOOOOOOOO  ',
  ' oOOOOOOOOOOOo ',
  '  OOOOOOOOOOO  ',
  '  oOOOOOOOOOo  ',
  '   OOOOOOOOO   ',
  '   oOOOOOOOo   ',
  '     oOOOo     ',
  '       o       ',
  '               '
]



);

my %symbols = 
(
  '' => [
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '               '
 ],

  '-a' => [
  '               ',
  '               ',
  '               ',
  '               ',
  '     ...       ',
  '    .***.      ',
  '     ...*.     ',
  '    .****.     ',
  '   .*...*.     ',
  '    .***.*.    ',
  '     ... .     ',
  '               ',
  '               ',
  '               ',
  '               '
 ],

  '-b' => [
  '               ',
  '               ',
  '               ',
  '    ..         ',
  '   .**.        ',
  '    .*..       ',
  '    .***.      ',
  '    .*..*.     ',
  '    .*..*.     ',
  '    .*..*.     ',
  '   .*.**.      ',
  '    . ..       ',
  '               ',
  '               ',
  '               '
 ],

  '-c' => [
  '               ',
  '               ',
  '               ',
  '               ',
  '               ',
  '      ..       ',
  '     .**.      ',
  '    .*..       ',
  '    .*..       ',
  '    .*..       ',
  '     .**.      ',
  '      ..       ',
  '               ',
  '               ',
  '               '
 ],

  '-d' => [
  '               ',
  '               ',
  '               ',
  '        ..     ',
  '       .**.    ',
  '      ..*.     ',
  '     .***.     ',
  '    .*..*.     ',
  '    .*..*.     ',
  '    .*..*.     ',
  '     .**.*.    ',
  '      .. .     ',
  '               ',
  '               ',
  '               '
 ],

  '-0' => [
  '               ',
  '               ',
  '               ',
  '      ...      ',
  '     .***.     ',
  '    .*...*.    ',
  '    .*..**.    ',
  '    .*.*.*.    ',
  '    .**..*.    ',
  '    .*...*.    ',
  '     .***.     ',
  '      ...      ',
  '               ',
  '               ',
  '               '
 ],
  '-1' => [
  '               ',
  '               ',
  '               ',
  '       .       ',
  '      .*.      ',
  '     .**.      ',
  '      .*.      ',
  '      .*.      ',
  '      .*.      ',
  '      .*.      ',
  '     .***.     ',
  '      ...      ',
  '               ',
  '               ',
  '               '
 ],
  '-2' => [
  '               ',
  '               ',
  '               ',
  '      ...      ',
  '     .***.     ',
  '    .*...*.    ',
  '     . ..*.    ',
  '      .**.     ',
  '     .*...     ',
  '    .*...*.    ',
  '    .*****.    ',
  '     .....     ',
  '               ',
  '               ',
  '               '
 ],
  '-3' => [
  '               ',
  '               ',
  '               ',
  '      ...      ',
  '     .***.     ',
  '    .*...*.    ',
  '     . ..*.    ',
  '      .**.     ',
  '     . ..*.    ',
  '    .*...*.    ',
  '     .***.     ',
  '      ...      ',
  '               ',
  '               ',
  '               '
 ],
  '-4' => [
  '               ',
  '               ',
  '               ',
  '        ..     ',
  '       .**.    ',
  '      .*.*.    ',
  '     .*..*.    ',
  '    .******.   ',
  '     ....*.    ',
  '       ..*.    ',
  '      .****.   ',
  '       ....    ',
  '               ',
  '               ',
  '               '
 ],
  '-5' => [
  '               ',
  '               ',
  '               ',
  '     .....     ',
  '    .*****.    ',
  '    .*....     ',
  '    .*...      ',
  '    .****.     ',
  '     ....*.    ',
  '     ....*.    ',
  '    .****.     ',
  '     ....      ',
  '               ',
  '               ',
  '               '
 ],
  '-6' => [
  '               ',
  '               ',
  '               ',
  '      ...      ',
  '     .***.     ',
  '    .*...*.    ',
  '    .*....     ',
  '    .****.     ',
  '    .*...*.    ',
  '    .*...*.    ',
  '     .***.     ',
  '      ...      ',
  '               ',
  '               ',
  '               '
 ],
  '-7' => [
  '               ',
  '               ',
  '               ',
  '      ...      ',
  '     .***.     ',
  '    .*...*.    ',
  '     . .*.     ',
  '      .*.      ',
  '      .*.      ',
  '      .*.      ',
  '      .*.      ',
  '       .       ',
  '               ',
  '               ',
  '               '
 ],
  '-8' => [
  '               ',
  '               ',
  '               ',
  '      ...      ',
  '     .***.     ',
  '    .*...*.    ',
  '    .*...*.    ',
  '     .***.     ',
  '    .*...*.    ',
  '    .*...*.    ',
  '     .***.     ',
  '      ...      ',
  '               ',
  '               ',
  '               '
 ],
  '-9' => [
  '               ',
  '               ',
  '               ',
  '      ...      ',
  '     .***.     ',
  '    .*...*.    ',
  '    .*.. *.    ',
  '     .****.    ',
  '     ....*.    ',
  '    .*...*.    ',
  '     .***.     ',
  '      ...      ',
  '               ',
  '               ',
  '               '
 ]

);

sub compose
{
  (my $bg, my $fg, my $sym) = @_;
  my $result = [ ];

  my $j = 0;

  while ($j <= $#$bg)
  {
    my $bgline = $bg->[$j];
    my $fgline = $fg->[$j];
    my $rline = '';
    $j++;

    my $i = 0;
    while ($i < length($bgline))
    {
      my $bgc = substr($bgline,$i,1);
      my $fgc = substr($fgline,$i,1);

      if($fgc eq ' ')
      {
        $rline .= $bgc;
      }
      elsif ($fgc eq '.')
      {
        $rline .= $cbmap{$sym};
      }
      elsif ($fgc eq '*')
      {
        $rline .= $cfmap{$sym};
      }
      else
      {
        $rline .= $fgc;
      }
      $i++;
    }
    push @$result, $rline;
  }

  return $result;
}

foreach my $file(keys %images)
{

 foreach my $ctype (keys %counters)
 {
  foreach my $symbol (keys %symbols)
  {
   my $fh = new FileHandle;
   $fh->open ('> '.$file.$ctype.$symbol.'.ppm');
  
   print $fh "P3\n";
   print $fh "# go\n";
   print $fh "15 15\n";
   print $fh "255\n";

   print "$file$ctype$symbol\n";

   my $image = compose($images{$file},$counters{$ctype},$ctype);
   $image = compose($image, $symbols{$symbol},$ctype);

   foreach my $line (@$image)
   {
    my $i = -1;
    while (++$i < length($line))
    {
      print $fh $map{substr($line,$i,1)};
    }
   } 
   $fh->close;
  }
 }
}





You're unlikely to find a '2gif' program for download nowadays - the whole freesource community is boycotting the gif format, since the new owners of the format tried to start enforcing licensing fees.

Not to say there aren't any, but you may as well jump to .png like everyone else is anyway.

''Tried that..
Google: ppm2png
..no luck :(''

To answer your edit summary, I think png will be fine in most browsers nowadays unless you use the variable transparency option.  I think IE might have got that one working too, but I have no idea about the other browsers. -- Kazuhiko

ec2-3-80-4-76.compute-1.amazonaws.com | ToothyWiki | ToothyWikiInternals | RecentChanges | Login | Webcomic
Edit this page | View other revisions | Recently used referrers
Last edited November 19, 2002 12:10 am (viewing revision 6, which is the newest) (diff)
Search: