-
-
Save chandeeland/9355140 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/perl | |
use 5.010; | |
use strict; | |
use warnings; | |
# use Data::Dump; | |
use DBI; | |
use SVG; | |
my $svg = SVG->new(width=>800,height=>800); | |
$svg->rect( x=>1, y=>1, width=>800, height=>800 ); | |
my $players = [qw/kwksilver philly deadlock/]; | |
my $host = 'localhost'; | |
my $pass = q//; | |
for my $player (@$players) { | |
my $dbh = DBI->connect('dbi:Pg:host='.$host.';database=schemaverse',$player,$pass) or die "$!"; | |
my $sth = $dbh->prepare(q" | |
select ship_id s, string_agg(tic::text,';') t, string_agg(a.x,';') x, string_agg(a.y,';') y from ( | |
select ship_id, tic, | |
round( ( 800 / ( 2e7 / ( (location_x+1) + 1e7 ) ) )::numeric, 4 )::text x, | |
round( ( 800 / ( 2e7 / ( (location_y+1) + 1e7 ) ) )::numeric, 4 )::text y | |
from my_ships_flight_recorder | |
order by ship_id,tic | |
)a | |
group by ship_id | |
having count(*) > 1 | |
; | |
"); | |
$sth->execute(); | |
my $r = $sth->fetchall_arrayref({}); | |
my $p = $dbh->selectcol_arrayref(q/select get_player_id(?)/, undef, $player)->[0]; | |
my $player_rgb = $dbh->selectcol_arrayref(q/select get_player_rgb(get_player_id(?));/, undef, $player )->[0]; | |
my $svgg = $svg->group( id => 'p'.$p ); | |
for(@$r) { | |
my $xv = [ split ';', $_->{x} ]; | |
my $yv = [ split ';', $_->{y} ]; | |
my $points = $svgg->get_path( | |
x=>$xv,y=>$yv,type=>'polyline' | |
); | |
my $path = $svgg->path( | |
%$points, | |
id=>'s'.$_->{s}, | |
style=>{ | |
'fill' => 'none', | |
'stroke' => '#'.$player_rgb, | |
'stroke-width' => 1, | |
}); | |
$path->animate( | |
attributeName => 'keySplines', | |
values => $_->{t}, | |
dur => '200s', | |
calcMode => 'spline', | |
repeatCount => 'indefinite' | |
); | |
} | |
} | |
say $svg->render(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment