NAME

CairoX::Sweet::Path - Handles a path

VERSION

Version 0.0200, released 2016-08-22.

SYNOPSIS

    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);

ATTRIBUTES

move => [x, y]

Array reference of two numbers. Optional, can't be used together with start.

Sets the starting position of the path to x and y points from the current position.

    $path = CairoX::Sweet::Path->new(move => [35, 50], ...);

start = [x, y]

Array reference of two numbers. Optional, can't be used together with 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], ...);

color => Color

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.

    $path = CairoX::Sweet::Path->new(color => '#8855bb', ...);

background_color => Color

A color. Optional. See CairoX::Sweet::background_color for more information on colors.

Sets the background color. If background_color is given, fill will be called on the path.

    $path = CairoX::Sweet::Path->new(background_color => [240, 245, 240], ...);

width => x

A number. Optional. Sets the pen width.

    $path = CairoX::Sweet::Path->new(width => 10, ...);

cap => cap_type

One of butt, round or square.

join => join_type

One of miter, round or bevel.

METHODS

add_line(x1, y1, x2, y2, ...)

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.

add_relative_line(x1, y1, x2, y2, ...)

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_curve(bezier_1ax, bezier_1ay, bezier_1bx, bezier_1by, x1, y1, ...)

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
    /);

add_relative_curve(bezier_1ax, bezier_1ay, bezier_1bx, bezier_1by, x1, y1, ...)

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_move(x, y)

Moves the current position x/y points from the current position.

add_start(x, y)

Moves the current position to x/y from the 0/0 point.

move_path(x => 30, y => 30)

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:

purge()

Empties lines and curves.

SEE ALSO

SOURCE

https://github.com/Csson/p5-CairoX-Sweet

HOMEPAGE

https://metacpan.org/release/CairoX-Sweet

AUTHOR

Erik Carlsson <info@code301.com>

COPYRIGHT AND LICENSE

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.