openSVG( 450, 450 ); openG( transform => 'translate(10,85) scale(1,-1)' ); openG( transform => 'scale(5)' ); foreach ( -15 .. 15 ) { hline( 0, 80, $_ ); } foreach ( 0 .. 80 ) { vline( -15, 15, $_ ); } path( d => 'M -1 0 H 81', style => 'stroke: red; stroke-opacity: .25; stroke-width: .1' ); graphline( 'black', 0.1, @scores ); graphline( 'green', 0.1, @bestblack ); graphline( 'red', 0.1, @bestwhite ); closeG(); closeG(); closeSVG(); sub path { openTAG( 'path', @_ ); closeTAG(); } sub openTAG { my $tag = shift; my %attributes = @_; print "<$tag"; foreach ( keys %attributes ) { print " $_=\"$attributes{$_}\""; } } sub closeTAG { my $s = shift; if ($s) { print "\n"; } else { print "/>\n"; } } sub openG { openTAG( 'g', @_ ); print ">\n"; } sub closeG { closeTAG('g'); } sub openSVG { my $height = shift; my $width = shift; print "\n"; print "\n"; print "\n"; } sub closeSVG { closeTAG('svg'); } sub hline { my ( $x1, $x2, $y1, $color ) = @_; if ($color) { path( d => "M $x1,$y1 H $x2", style => "stroke: $color;" ); } else { path( d => "M $x1,$y1 H $x2" ); } } sub vline { my ( $y1, $y2, $x1, $color ) = @_; if ($color) { path( d => "M $x1,$y1 V $y2", style => "stroke: $color;" ); } else { path( d => "M $x1,$y1 V $y2" ); } } sub graphline { my $color = shift; my $width = shift; my @values = @_; my @list; my $y = 0; foreach (@values) { if ($_) { push ( @list, $y ); push ( @list, $_ ); } $y++; } openTAG( 'polyline', points => join ( ',', @list ), style => "stroke: $color; stroke-width: $width; fill: none;", ); closeTAG(); }