From: Shiar Date: Wed, 14 Nov 2007 07:55:33 +0000 (+0100) Subject: screp --act to create an animated image of replay actions X-Git-Url: http://git.shiar.nl/perl/schtarr.git/commitdiff_plain/15cda388e4c1449875ffc4a7fc94b76ea32ee74d screp --act to create an animated image of replay actions Creates an animated GIF using GD, with pixels set at move/attack/builds locations for each player per time period. Could use some love. --- diff --git a/screp b/screp index 93eb14f..5e754ad 100755 --- a/screp +++ b/screp @@ -4,12 +4,14 @@ use warnings; use Data::Dumper; my $SHOWWARN = 0; +my $ACTGIF = undef; my $APMSVG = undef; use Getopt::Long; GetOptions( "verbose|v!" => \$SHOWWARN, "apm|a=s" => \$APMSVG, + "act" => \$ACTGIF, ); use constant { APM_FIRSTFRAME => 80 / .042 }; @@ -559,6 +561,53 @@ for my $player (sort keys %stats) { ) if 0; } +if ($ACTGIF) { + open my $imgfile, '>', "test.gif" or die; + binmode $imgfile; + select $imgfile; + + use GD; + my $ani = GD::Image->new($head->{width}, $head->{height}); + my $bg = $ani->colorAllocate(0, 0, 0); + my @plot = ( + $ani->colorAllocate(255, 0, 0), + $ani->colorAllocate(255, 255, 0), + $ani->colorAllocate(0, 255, 0), + $ani->colorAllocate(0, 255, 255), + $ani->colorAllocate(0, 0, 255), + $ani->colorAllocate(255, 0, 255), + ); + + print $ani->gifanimbegin; +# print $ani->gifanimadd; + { + my $frame = GD::Image->new($ani->getBounds); + print $frame->gifanimadd; + my $length = 30 / .042; + my $last = 0; + for (@$map) { + my ($time, $player, $cmd, @data) = @$_; +#$time < $length * 10 or last; + while ($time > $last + $length) { + $last += $length; + print $frame->gifanimadd(0, 0, 0, 32); +# $frame = GD::Image->new($ani->getBounds); + } + if ($cmd eq "build") { + $frame->setPixel($data[1]>>5, $data[2]>>5, $plot[$player]); + } + elsif ($cmd eq "move" or $cmd eq "attack") { + $frame->setPixel($data[0]>>5, $data[1]>>5, $plot[$player]); +# if $data[2] == 0xFFFF_FFFF; + } + } +# add_frame_data($frame); + print $frame->gifanimadd; + } + print $ani->gifanimend; + select STDOUT; +} + if ($APMSVG) { my @seq; # player => time (s) => actions $seq[$_->[1]][$_->[0] * .042]++ for @$map;