Search notes:
Perl module SVG
#!/usr/bin/perl
use warnings;
use strict;
use SVG;
my $svg= SVG->new(
width =>1000,
height=> 600
);
my $line_1 = $svg->line (
id => 'line_1',
x1 => 30, y1 => 30,
x2 => 970, y2 => 570,
style=>{
'stroke' =>'rgb(255, 127, 0)',
'stroke-width'=> 15
}
);
die unless $line_1->isa('SVG::Element');
my $line_2 = $svg->line (
id => 'line_2',
x1 => 970, y1 => 30,
x2 => 30, y2 => 570,
);
$line_2->STYLE(
'stroke' =>'rgb( 63, 127, 255)',
'stroke-width'=> 15);
my $svg_text = $svg -> xmlify;
open (my $svg_h, '>', 'script-out.svg') or die;
print $svg_h $svg_text;
close $svg_h;
circle
#!/usr/bin/perl
use warnings;
use strict;
use SVG;
use Math::Trig;
my $size_svg = 1000;
my $svg = SVG->new (
width =>$size_svg,
height=>$size_svg
);
for (1 .. 100) {
my $angle = 2.0 * pi * rand;
my $x = $size_svg / 2 + $size_svg * 0.30 * sin($angle) + 0.15 * $size_svg * rand;
my $y = $size_svg / 2 + $size_svg * 0.30 * cos($angle) + 0.15 * $size_svg * rand;
$svg->circle(
cx => $x,
cy => $y,
r => 8.0* rand() + 4,
style=> {
fill => sprintf('rgb(%d, %d, %d)', int(200*rand), int(200*rand), int(200*rand))
}
);
}
my $svg_text = $svg->xmlify;
open (my $svg_h, '>', 'circle.svg') or die;
print $svg_h $svg_text;
close $svg_h;
polyline
#!/usr/bin/perl
use warnings;
use strict;
use SVG;
use Math::Trig;
my $svg = SVG->new (
width =>500,
height=>500
);
my $nof_points = 19;
my $skip = 5;
my $points = '';
for (my $i = 0; $i<=$nof_points; $i++) {
my $x = 250 + sin(2*pi / $nof_points * $skip * $i) * 230;
my $y = 250 + cos(2*pi / $nof_points * $skip * $i) * 230;
$points .= ' ' if $points;
$points .= "$x,$y";
}
$svg->polyline(
points=>$points,
style=>{
'stroke' => 'rgb(255, 127, 0)',
'stroke-width' => '5px',
'fill' => 'none',
}
);
my $svg_text = $svg->xmlify;
open (my $svg_h, '>', 'polyline.svg') or die;
print $svg_h $svg_text;
close $svg_h;