# radar
#!/usr/bin/perl
#
# Feb 2002 - Ico Doornekamp - Zeff@zevv.nl
#

$|=1;

$xmax = 320;
$ymax = 240;
$fontfile = "./Courier-New.fdb";
$textstring = "RADAR";
$fontfile ="/usr/share/libming/fonts/openOfficeTTF/Conga.fdb";
$textsize = 40;

###########################################

use CGI;
use SWF;
use SWF::Font;
use SWF::Shape;
use Socket;

$q = new CGI;
$t = $q->param('t');

SWF::setScale(1.0);
$xcen = $xmax/2;
$ycen = $ymax/2;

print "Content-type: application/x-shockwave-flash\n\n";

my $m = new SWF::Movie();
$m->setRate(25);
$m->setDimension($xmax, $ymax);
$m->setBackground(0,0,0);

$grad = new SWF::Gradient();
$grad->addEntry(0, 0, 150, 0, 0xff);
$grad->addEntry(.5, 0, 0, 0 , 0xff);
$ding = new SWF::Shape();
$fill = $ding->addFill($grad, 0x12);
$fill->scaleTo(0.0005);
$ding->setRightFill($fill);
#$ding->setLine(1,0,105,0);
circle($ding, 0, 0, 4);

for($i=0; $i<20; $i++) {
        $iding = $m->add($ding);
        $r = rand(100);
        $a = rand(360)/180*3.1415;

        $iding->moveTo(sin($a)*$r + $xcen ,cos($a)*$r + $ycen);
}


$text = new SWF::Text();
$font = new SWF::Font($fontfile);
$text->setFont($font);
$text->setColor(0,255,0);
$text->setHeight($textsize);
$text->moveTo(-$font->getWidth($textstring)/(2000/$textsize), 15);
$text->addString($textstring);

$itext = $m->add($text);
$itext->moveTo($xcen, $ycen);




$mask = new SWF::Bitmap("data/black.jpg", "data/radarmask.msk");

$circle = new SWF::Shape();
$fill=$circle->addFill($mask);
$fill->scaleTo(1);
$fill->moveTo(-250,-250);
$circle->setRightFill($fill);
circle($circle, 0, 0, 100);

$icircle = $m->add($circle);
$icircle->moveTo($xcen, $ycen);

for($i=0; $i<360; $i+=5) {
        $icircle->rotateTo(-$i);
        $m->nextFrame();
}

$m->output();


sub circle
{
        my($s, $x, $y, $r) = @_;

        $a = $r * 0.414213562;
        $b = $r * 0.707106781;

        $s->movePenTo($x+$r, $y);
        $s->drawCurveTo($x+$r, $y-$a, $x+$b, $y-$b);
        $s->drawCurveTo($x+$a, $y-$r, $x, $y-$r);
        $s->drawCurveTo($x-$a, $y-$r, $x-$b, $y-$b);
        $s->drawCurveTo($x-$r, $y-$a, $x-$r, $y);
        $s->drawCurveTo($x-$r, $y+$a, $x-$b, $y+$b);
        $s->drawCurveTo($x-$a, $y+$r, $x, $y+$r);
        $s->drawCurveTo($x+$a, $y+$r, $x+$b, $y+$b);
        $s->drawCurveTo($x+$r, $y+$a, $x+$r, $y);

}

