File: 03_circle_and_square.pl

package info (click to toggle)
libsvg-perl 2.87-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 464 kB
  • sloc: perl: 2,789; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 1,730 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/perl

use strict;
use warnings;

use SVG;

# create an SVG object with a size of 100x100 pixels
my $svg = SVG->new(
    width  => 100,
    height => 100,
);

# create a rectangle (actually square) with the top left
# corner being at (40, 50)
# (0, 0) would mean being in the top left corner of the image.
# The width and the height of the rectangular are also given
# in pixels and we can add style just asw we  did with the circle.
$svg->rectangle(
    x => 40,
    y => 50,
    width  => 40,
    height => 40,
    style => {
        'fill'           => 'rgb(0, 255, 0)',
        'stroke'         => 'black',
        'stroke-width'   =>  0,
        'stroke-opacity' =>  1,
        'fill-opacity'   =>  1,
    },
);

$svg->circle(
    cx => 40,
    cy => 40,
    r  => 20,
    style => {
        'fill'           => 'rgb(255, 0, 0)',
        'stroke'         => 'black',
        'stroke-width'   =>  0,
        'stroke-opacity' =>  1,
        'fill-opacity'   =>  1,
    },
);

# In order to create a triangle we are going to create a polygon
# To make it easy to create various path based constructs, SVG.pm
# provides a "get_path" method that, give a series of coordinates
# and a type, return the respective data structure that is needed
# for SVG.
my $path = $svg->get_path(
    x => [40, 60, 80],
    y => [40, 6, 40],
    -type => 'polygon');

# Then we use that data structure to create a polygon
$svg->polygon(
    %$path,
    style => {
        'fill'           => 'rgb(0,0,255)',
        'stroke'         => 'black',
        'stroke-width'   =>  0,
        'stroke-opacity' =>  1,
        'fill-opacity'   =>  1,
    },
);

# now render the SVG object, implicitly use svg namespace
print $svg->xmlify, "\n";