#!/usr/local/bin/perl
#+JMJ
# qdstar2 - Quick and Dirty Starfield Generator Version 2
#           Improve eficiency by generating starfield in
#           single pass without saving in memory.

$ROWS=24;
$COLS=69;
$OPAC=0.07;

for $r (0..$ROWS-1)
{
   for $c (0..$COLS-1)
   {
       if ( rand() >= $OPAC ) { print " "; }
       else
       {
           $mag=rand();
           if ($mag < 0.5)         { $s = '.'; }
           elsif ($mag < 0.75)     { $s = ','; }
           elsif ($mag < 0.875)    { $s = 'o'; }
           elsif ($mag < 0.9375)   { $s = '*'; }
           elsif ($mag < 0.96875)  { $s = 'O'; }
           elsif ($mag < 0.984375) { $s = '0'; }
           else                    { $s = '@'; }
           print $s;
       }
   }
   print "\n";
}