NAME

Math::ColorRGBA - Perl class to represent rgba colors

TREE

-+- Math::Vector -+- Math::Vec4 -+- Math::ColorRGBA

REQUIRES

Math::Color

SEE ALSO

PDL for scientific and bulk numeric data processing and display

Math

Math::Vectors

Math::Color, Math::ColorRGBA, Math::Image, Math::Vec2, Math::Vec3, Math::Rotation

SYNOPSIS

use Math::ColorRGBA;
my $c = new Math::ColorRGBA;  # Make a new Color

my $c1 = new Math::ColorRGBA(0,1,0,0);

DESCRIPTION

Default value

0 0 0 0

OPERATORS

Summary

METHODS

new(r,g,b,a)

r, g, b, a are given on [0, 1].

my $c = new Math::ColorRGBA; 					  
my $c2 = new Math::ColorRGBA(0, 0.5, 1, 0);   
my $c3 = new Math::ColorRGBA([0, 0.5, 1, 1]); 

copy

Makes a copy

$c2 = $c1->copy;

setValue(r,g,b,a)

Sets the value of the color. r, g, b, a are given on [0, 1].

$c1->setValue(0, 0.2, 1, 0);

setRGB

Sets the value of the color from a 3 component array ref ie. (Math::Color).

$c4->setRGB(new Math::Color(0.1,0.2,0.3));

setRed(r)

Sets the first value of the color r is given on [0, 1].

$c1->setRed(1);

setGreen(g)

Sets the second value of the color. g is given on [0, 1].

$c1->setGreen(0.2);

setBlue(b)

Sets the third value of the color. b is given on [0, 1].

$c1->setZ(0.3);

setAlpha(alpha)

Sets the fourth value of the color. a is given on [0, 1].

$v1->setAlpha(1);

getValue

Returns the value of the color (r, g, b, a) as a 4 components array.

@v = $c1->getValue;

getRGB

Returns the rgb value of the color (r, g, b) as color (Math::Color).

$c = $c4->getRGB;

getRed

Returns the first value of the color.

$r = $c1->getRed;

getGreen

Returns the second value of the color.

$g = $c1->getGreen;

getBlue

Returns the third value of the color.

$b = $c1->getBlue;

getAlpha

Returns the fourth value of the color.

$a = $v1->getAlpha;

setHSV(h,s,v,a)

h is given on [0, 2 PI]. s, v are given on [0, 1].

$c->setHSV(1/12,1,1);  # 1 0.5 0
$c->setHSV(h,s,v);
$c->setHSV(h,s,v,a);

getHSV

h is in [0, 2 PI]. s, v are each returned on [0, 1].

@hsv = $c->getHSV;

inverse

Returns the inverse of the color. Inverses the RGB components. Alpha is left unchanged. This is used to overload the '~' operator.

$v = new Math::ColorRGBA(0, 0.1, 1, 0.123);
$v = $v1->inverse;  # 1 0.9 0 0.123
$v = ~$v1;          # 1 0.9 0 0.123

add(Math::ColorRGBA)

Adds the RGB components. Alpha is taken from the first color.

$v = $v1->add($v2);
$v = $v1 + $v2;
$v = [0.8, 0.2, 0.4, 0.1] + $v1;
$v1 += $v2;

subtract(Math::ColorRGBA)

Subtracts the RGB components of the two colors. Alpha is taken from the first color.

$v = $v1->subtract($v2);
$v = $v1 - $v2;
$v = [0.8, 0.2, 0.4, 0.2] - $v1;
$v1 -= $v2;

multiply(Math::ColorRGBA or scalar)

This is used to overload the '*' operator. Multiplies the RGB components. Alpha is left unchanged.

$v = $v1 * 2;
$v = $v1 * [0.3, 0.5, 0.4, 0.2];
$v = [0.8, 0.2, 0.4, 0.2] * $v1;
$v = $v1 * $v1;
$v1 *= 2;

$v = $v1->multiply(2);

divide(Math::ColorRGBA or scalar)

Divides the RGB components. Alpha is left unchanged. This is used to overload the '/' operator.

$v = $v1 / 2;
$v1 /= 2;
$v = $v1 / [0.3, 0.7, 0.4, 0.2];
$v = [0.8, 0.2, 0.4, 0.2] / $v1;
$v = $v1 / $v1;

$v = $v1->divide(2);

toString

Returns a string representation of the color. This is used to overload the '""' operator, so that color may be freely interpolated in strings.

my $c = new Math::ColorRGBA(0.1, 0.2, 0.3);
print $c->toString; # "0.1, 0.2, 0.3"
print "$c";         # "0.1, 0.2, 0.3"

SEE ALSO

PDL for scientific and bulk numeric data processing and display

Math

Math::Vectors

Math::Color, Math::ColorRGBA, Math::Image, Math::Vec2, Math::Vec3, Math::Rotation

BUGS & SUGGESTIONS

If you run into a miscalculation, need some sort of feature or an additional holiday, or if you know of any new changes to the funky math, please drop the author a note.

ARRANGED BY

Holger Seelig holger.seelig@yahoo.de

COPYRIGHT

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