#!/usr/bin/perl

#
#  Draw NIMBI board
#
#  The image will be 1600x1600, rescale it to 400x400
#  to get antialiasing
#

$width = 1600;
$height = 1600;
$radius = $width/2 - 200;
$lradius = 24;
$side = 300;
use GD::Simple;

$img = GD::Simple->new($width, $height);

#  black background

$img->bgcolor('black');
$img->fgcolor('black');
$img->rectangle(0,0,$width-1,$height-1);

#  white circle in center

$img->moveTo($width/2,$height/2);
$img->bgcolor('white');
$img->fgcolor('white');
$img->ellipse($radius*2,$radius*2);

#  Turtle stuff

$img->fgcolor('black');

$img->moveTo($width/2, $height/2);
$img->penSize(8,8);
$img->fgcolor('black');
$img->angle(-90);
$img->turn($i*120);
$img->move($side/2);
$img->fgcolor('black');
$img->turn(-30);
$img->move($side);
$img->turn(120);
# We are now at upper left corner
for($i=0;$i<3;$i++)
{
  if($i==0)
  {
    ($x[28],$y[28]) = $img->curPos;
  }
  $img->line($side);
  if($i==0)
  {
    ($x[29],$y[29]) = $img->curPos;
  }
  $img->turn(60);
  $img->move($side);
  $img->turn(120);
  if($i==0)
  {
    ($x[35],$y[35]) = $img->curPos;
  }
  $img->line($side);
  $img->turn(0);
  if($i==0)
  {
    ($x[30],$y[30]) = $img->curPos;
  }
  $img->line($side);
  if($i==0)
  {
    ($x[39],$y[39]) = $img->curPos;
  }
  $img->turn(-60);
  $img->move($side);
  $img->turn(-120);
  if($i==0)
  {
    ($x[33],$y[33]) = $img->curPos;
  }
  $img->line($side);
  $img->turn(0);
  if($i==0)
  {
    ($x[34],$y[34]) = $img->curPos;
  }
  $img->line($side);
  if($i==0)
  {
    ($x[38],$y[38]) = $img->curPos;
  }
  $img->line($side);
  if($i==0)
  {
    ($x[36],$y[36]) = $img->curPos;
  }
  $img->turn(120);
  $img->move($side);
  $img->turn(60);
  if($i==0)
  {
    ($x[37],$y[37]) = $img->curPos;
  }
  $img->line($side);
  $img->turn(0);
  if($i==0)
  {
    ($x[31],$y[31]) = $img->curPos;
  }
  $img->line($side);
  if($i==0)
  {
    ($x[32],$y[32]) = $img->curPos;
  }
  $img->turn(60);
}

for($i=28;$i<=39;$i++)
{
  $img->moveTo($x[$i],$y[$i]);
  $img->bgcolor('black');
  $img->fgcolor('black');
  $img->ellipse($lradius,$lradius);
  $x1 = int($x[$i]*0.25+0.5);
  $y1 = int($y[$i]*0.25+0.5);
  printf STDERR "#define NIMBI_${i}x $x1\n";
  printf STDERR "#define NIMBI_${i}y $y1\n";
}

$img->angle(0);
$img->turn(0);
$img->fgcolor('white');
$img->bgcolor('white');
$font = $img->font("Courier-Bold", 40);
$img->moveTo(60,150);
$img->string("Nyt spil");
$img->moveTo(364,130);
($x[0],$y[0]) = $img->curPos;
$img->ellipse($lradius*2,$lradius*2);
$x1 = int($x[0]*0.25+0.5);
$y1 = int($y[0]*0.25+0.5);
printf STDERR "#define NIMBI_newgamex $x1\n";
printf STDERR "#define NIMBI_newgamey $y1\n";

$img->moveTo(1300,150);
$img->string("Svar");
$img->moveTo(1236,130);
($x[1],$y[1]) = $img->curPos;
$img->ellipse($lradius*2,$lradius*2);
$x1 = int($x[1]*0.25+0.5);
$y1 = int($y[1]*0.25+0.5);
printf STDERR "#define NIMBI_answerx $x1\n";
printf STDERR "#define NIMBI_answery $y1\n";

print $img->png;

