Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Code Maven logo using Perl

Code Maven logo

The code:

In this case it was written in Perl, but we have examples in other languages as well.

use strict;
use warnings;
use SVG (-nocredits => 1, -inline => 1);

my $size = 490;

my $svg = SVG->new(
    width   => $size,
    height  => $size,
    viewBox => "0 0 $size $size",
);

my $blue = 'rgb(44, 122, 186)';

my $left_padding = 37;
my $middle = 248;
my $width = 42;
my $right_padding = 40;
my $xyz = $size - $right_padding - $width;
my $top = 72;
my $bottom = 416;
my $hump = 48;

add_poly(
        [ $left_padding,          $middle ],
        [ 213,                    $top ],
        [ 235,                    93 ],
        [ $left_padding + $width, $middle ],
        [ 235,                    396 ],
        [ 213,                    $bottom ],
);
add_poly(
        [ 285,                    93 ],
        [ 306,                    $top ],
        [ $size - $right_padding, $middle - $hump ],
        [ $xyz,                   $middle ], # middle of M right
        [ $size - $right_padding, $middle + $hump ],
        [ 306,                    $bottom ],
        [ 285,                    396 ],
        [ $xyz,                   $middle + $hump ],
        [ $xyz - $width,          $middle ], # middle of M left
        [ $xyz,                   $middle - $hump ],
    );

print $svg->xmlify();

sub add_poly {
    my @pairs = @_;

    my $points = join " ", map { join ",", @$_ } @pairs;
    $svg->polygon(
        points => $points,
        fill => $blue,
    );
}

The SVG

<svg height="490" viewBox="0 0 490 490" width="490" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
	<polygon fill="rgb(44, 122, 186)" points="37,248 213,72 235,93 79,248 235,396 213,416" />
	<polygon fill="rgb(44, 122, 186)" points="285,93 306,72 450,200 408,248 450,296 306,416 285,396 408,296 366,248 408,200" />
</svg>