#!/usr/bin/perl

$X = 500;
$Y = 300;

$D = $X*$Y/10;   # Total number of dots 

# Initialize canvas.    The ieral string is the background color.
@C = ("\377\377\377" x $X) x $Y;
my $sf = 1/2; # fraction of picture that is symmetrical
my $sp = (1-$sf)/(1+$sf);
my $symm = $X * $sf;

while ($D > 0) {
  my ($x, $y);
  my $g = chr(rand(255)) . chr(rand(255)) . chr(rand(255));
  if (rand() < $sp) {           # Put a pair of dots in the symmetrical region
    do {
      $x = int rand($X);
      $y = int rand($Y);
    } while $x < ($X-$symm)/2 || $x > ($X+$symm)/2;
    blot($x, $y, $g);
    blot($X-$x, $y, $g);
    $D-=2;
  } else {                      # Put a dot in the asymmetrical region
    do {
      $x = int rand($X);
      $y = int rand($Y);
    } until $x < ($X-$symm)/2 || $x > ($X+$symm)/2;
    blot($x, $y, $g);
    $D-=1;
  }
}

sub blot {
  my ($x, $y, $g) = @_;
  return unless $x > 0 && $y > 0 && $x < $X-1 && $y < $Y-1;
  for $xx (-1..1) {
    for $yy (-1..1) {
      substr($C[$y+$yy], 3*($x+$xx), 3) = $g;
    }
  }
}

print "P6\n$X $Y\n255\n";
print @C;
