NAME

SWF::Builder::Gradient - SWF gradient object.

SYNOPSIS

    my $gr = $mc->new_gradient;
    $gr->add_color(   0 => '000000',
		     98 => '0000ff',
		    128 => 'ff0000',
		    158 => '0000ff',
		    255 => '000000',
		   );

    my $gm = $gr->matrix;
    my $shape = $mc->new_shape
        ->fillstyle($gr, 'linear', $gm)
        ->moveto( ... )
        ->lineto( ... )-> ... ;
    $gm->fit_to_rect(longer => $shape->get_bbox);

DESCRIPTION

Gradient object is a kind of fill styles of shapes. Colors are interpolated between the control points determined by ratios. Each gradient has 1-8 control points.

$gr = $mc->new_gradient

returns a new gradient object.

$gr->add_color( $ratio, $color [, $ratio, $color ...])

adds control points of the gradient. $ratio is a position of the point. 0 maps to left/center and 255 to right/outer for linear/radial gradient. $color can take a six or eight-figure hexadecimal string, an array reference of R, G, B, and optional alpha value, an array reference of named parameters such as [Red => 255], and SWF::Element::RGB/RGBA object.

$gm = $gr->matrix

returns a transformation matrix for the gradient.

$gm->fit_to_rect( $mode => @rect )

transforms the gradient matrix to fit to the rectangle. $mode can take as follows:

fit

to fit the gradient square to the rectangle. It does not keep proportion.

width

to fit the gradient square to the width of the rectangle, and scales it with keeping proportion.

height

to fit the gradient square to the height of the rectangle, and scales it with keeping proportion.

longer

to fit the gradient square to the longer side of the rectangle, and scales it with keeping proportion.

shorter

to fit the gradient square to the shorter side of the rectangle, and scales it with keeping proportion.

COPYRIGHT

Copyright 2003 Yasuhiro Sasama (ySas), <ysas@nmt.ne.jp>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.