#!/usr/bin/perl

# Andrew Daviel, April 2005
# generate big HTML page from Google satellite images
# hard-coded for area around UBC, Vancouver
# change $pfx values for other areas

%iv = ('q','r','s','t','t','s','r','q') ;
$br = shift ;  # border between tiles (required for later sat2fig)
$br += 0 ;
print<<EOT;
<html><head>
<base href="http://kh.google.com/kh">
</head><body>
EOT
$a= 'r' ;
$h=60 ; $w=60 ;

$pfx = 'tqtrtstqqtstsr' ;
#tsrttsq

draw('tqqq') ; # 0111
draw('tqqt') ; # 0110
draw('tqtq') ; # 0101
draw('tqtt') ; # 0100
draw('ttqq') ; # 0011
draw('ttqt') ; # 0010
draw('tttq') ; # 0001
draw('tttt') ; # 0000
$pfx = 'tqtrtstqqtstss' ;
# qrss is 16th/marine
draw('qqqq') ; # 1111
draw('qqqt') ; # 1110
draw('qqtq') ; # 1101
draw('qqtt') ; # 1100
draw('qtqq') ; # 1011
draw('qtqt') ; # triumf  1010
draw('qttq') ; # 1001
draw('qttt') ; # 1000
draw('tqqq') ; # 0111
draw('tqqt') ; # 0110
draw('tqtq') ;  # 0101
draw('tqtt') ; # 0100
draw('ttqq') ; # 0011
draw('ttqt') ; # 0010
draw('tttq') ; # 0001
draw('tttt') ; # 0000
#tqtrtstqqtstsssrrr
#tqtrtstqqtsstttqqs
print<<EOT;
</body></html>
EOT

sub draw {
  my $n = length($_[0]) ;
  my @a = split(//,$_[0]) ;
  my ($a,$b,$c,$d,$e,$f,$g) ;
  my %done ;
  print "<br>\n" ;
  foreach $a ($a[0],$iv{$a[0]}) {
    foreach $b ($a[1],$iv{$a[1]}) {  
      foreach $c ($a[2],$iv{$a[2]}) {
        foreach $d ($a[3],$iv{$a[3]}) {
          foreach $e ($a[4],$iv{$a[4]}) {
            foreach $f ($a[5],$iv{$a[5]}) {
              foreach $g ($a[6],$iv{$a[6]}) {
                $img = "$a$b$c$d$e$f$g" ;
                unless ($done{$img}) {
                  print "<img src=\"/kh?v=1&t=$pfx$img\" title=\"$img\" height=$h width=$w border=$br>" ;
                  $done{$img} = 1 ;
                  if ($br) { print "\n" ; }
                }
              }
            }
          }
        }
      }
    }
  }
}

