CairoX::Sweet::Path - Handles a path
Version 0.0200, released 2016-08-22.
use CairoX::Sweet; my $c = CairoX::Sweet->new(500, 500, '#ffffff'); my $path = CairoX::Sweet::Path->new(start => [35, 50], color => '#8855bb', width => 10, cap => 'round', join => 'round'); $path->add_relative_line(qw/ 20 -5 10 0 30 -20 -50 0 /); $c->add_path($path, close => 1);
Array reference of two numbers. Optional, can't be used together with start.
start
Sets the starting position of the path to x and y points from the current position.
x
y
$path = CairoX::Sweet::Path->new(move => [35, 50], ...);
Array reference of two numbers. Optional, can't be used together with move.
move
Sets the starting position of the path to x and y points from the [0, 0] point.
$path = CairoX::Sweet::Path->new(start => [135, 150], ...);
A color. Optional. See CairoX::Sweet::background_color for more information on colors.
Sets the pen color. stroke will always be called on the path, if color isn't set then the current color is used.
color
$path = CairoX::Sweet::Path->new(color => '#8855bb', ...);
Sets the background color. If background_color is given, fill will be called on the path.
background_color
$path = CairoX::Sweet::Path->new(background_color => [240, 245, 240], ...);
A number. Optional. Sets the pen width.
$path = CairoX::Sweet::Path->new(width => 10, ...);
One of butt, round or square.
butt
round
square
One of miter, round or bevel.
miter
bevel
The argument must be a list with an even number of items. The positions are absolute. Uses line_to in Cairo.
$path->add_line(qw/ 20 30 30 40 30 80 40 80 /);
Note that the line starts at the current position, usually set by move or start in the constructor.
Pushes a line onto the path. Note that any number of calls to the add_*_line, add_*_curve, add_start and add_move can be made. They will be combined into one path in the end.
The argument must be a list a number of items. Similar to add_line() except that the positions are relative to the previous current position. Uses line_rel_to in Cairo.
add_line()
The argument must be a list a number of items divisible by six. The positions are absolute. Uses curve_to in Cairo.
$path->add_curve(qw/ 441 157 461 149 457 135 454 119 434 113 421 109 422 105 423 101 424 97 424 87 416 83 408 84 /);
The argument must be a list a number of items divisible by six. Similar to add_curve() except that the positions are relative to the previous current position. Uses curve_rel_to in Cairo.
add_curve()
Moves the current position x/y points from the current position.
Moves the current position to x/y from the 0/0 point.
Moves all points in the path x and y points from their current positions. This means you can do this:
my $c = CairoX::Sweet->new(220, 130, background_color => '#ffffff'); my $path = CairoX::Sweet::Path->new(start => [25, 50], color => '#8855bb', width => 10, join => 'miter'); $path->add_line(qw/ 45 95 55 95 /); $path->add_curve(qw/ 70 110 90 90 100 100 110 90 110 90 120 90 130 80 130 80 140 105 155 120 170 80 185 75 /); $path->add_line(qw/ 185 45 150 10 135 20 /); $c->add_path($path, close => 1); $path->color('#bb99cc'); $path->join('round'); $path->cap('round'); $path->move_path(x => 12, y => 12); $c->add_path($path); $c->surface->write_to_png('image.png');
Which produces:
Empties lines and curves.
CairoX::Sweet::Path
Cairo
https://github.com/Csson/p5-CairoX-Sweet
https://metacpan.org/release/CairoX-Sweet
Erik Carlsson <info@code301.com>
This software is copyright (c) 2016 by Erik Carlsson.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install CairoX::Sweet, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CairoX::Sweet
CPAN shell
perl -MCPAN -e shell install CairoX::Sweet
For more information on module installation, please visit the detailed CPAN module installation guide.