SVG
view release on metacpan or search on metacpan
examples/inlinesvg.pl view on Meta::CPAN
my $xv = [$width*rand(), $width*rand(), $width*rand(), $width*rand()];
my $yv = [$height*rand(), $height*rand(), $height*rand() ,$height*rand()];
my $points = $a->get_path(x=>$xv,
y=>$yv,
-type=>'polyline',
-closed=>'true',);
$c = $a1->polyline (%$points,
id=>'pline1',
style=>&obj_style);
#---------
$xv = [$width*rand(), $width*rand(), $width*rand(), $width*rand()];
$yv = [$height*rand(), $height*rand(), $height*rand() ,$height*rand()];
$points = $a->get_path(x=>$xv,
y=>$yv,
-type=>'polygon',);
$c = $a->polygon (%$points,
id=>'pgon1',
style=>&obj_style);
#---------
my $t=$a2->text(id=>'t1',
transform=>'rotate(-45)',
style=>&text_style);
#---------
my $u=$a2->text(id=>'t3',
x=>$width/2*rand(),
y=>($height-80)*rand(),
transform=>'rotate('.(-2.5*5*rand()).')',
style=>&text_style);
my $v=$a2->tag('text',
id=>'t5',
x=>$width/2*rand(),
y=>$height-40+5*rand(),
transform=>'rotate('.(-2.5*5*rand()).')',
style=>&text_style);
my $w=$a2->text(id=>'t5',
x=>$width/2*rand(),
y=>$height-20+5*rand(),
transform=>'rotate('.(-2.5*5*rand()).')',
style=>&text_style);
$t->cdata('Text generated using the high-level "text" tag');
$t->cdata('Courtesy of RO IT Systems GmbH');
$v->cdata('Text generated using the low-level "tag" tag');
$w->cdata('But what about inline SVG? Yes, we do that too');
$w->cdata('All this with SVG.pm? Wow.');
print $p->header('image/svg-xml');
print $svg->render(-inline=>1);
exit;
#################
# Subroutine to round up the value of a number or of a text representation of number
#
sub round_up {
my ($x, $precision) = shift;
$x =~ s/^\s+//g;
$x =~ s/\s+$//g;
$x =~ s/,//g;
my $y;
$precision = 0 unless $precision;
($x, $y) = split( /\./, $x) if $x =~ /\./;
my $y1 = substr($y, 0, $precision);
my $y2 = substr($y, $precision, 1);
if ($y2 >= 5) {
$precision?$y1++:$x++;
}
return "$x$y1";
} # sub round_val
sub obj_style {
my $style = {'stroke-miterlimit'=>(4*rand()),
'stroke-linejoin'=>'miter',
'stroke-linecap'=>'round',
'stroke-width'=>(0.1+0.5*rand()),
'stroke-opacity'=>(0.5+0.5*rand()),
'stroke'=>'rgb('.255*round_up(rand()).','.255*round_up(rand()).','.255*round_up(rand()).')',
'fill-opacity'=>(0.5+0.5*rand()),
'fill'=>'rgb('.255*round_up(rand()).','.255*round_up(rand()).','.255*round_up(rand()).')',
'opacity'=>(0.5+0.5*rand()) };
return $style;
}
sub text_style {
my $style = {'font-family'=>'Arial',
'font-size'=>8+5*rand(),
'stroke-width'=>1+2*rand(),
'stroke-opacity'=>(0.2+0.5*rand()),
'stroke'=>'rgb('.255*round_up(rand()).','.255*round_up(rand()).','.255*round_up(rand()).')',
'fill-opacity'=>1,
'fill'=>'rgb('.255*round_up(rand()).','.255*round_up(rand()).','.255*round_up(rand()).')',
'opacity'=>(0.5+0.5*rand()) };
return $style;
}
( run in 1.070 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )