Class: GD2::Color

Class | GD2::Color
In: | lib/gd2/color.rb
Parent: | Object

# Description

Color objects hold the red, green, blue, and alpha components for a pixel color. Color objects may also be linked to a particular palette index associated with an image.

## Creating

Color objects are created by specifying the individual components:

      red   = Color[1.0, 0.0, 0.0]
      green = Color[0.0, 1.0, 0.0]
      blue  = Color[0.0, 0.0, 1.0]

      transparent_yellow = Color[1.0, 1.0, 0.0, 0.5]

The components may be specified as a percentage, as an explicit value between 0..RGB_MAX or 0..ALPHA_MAX, or as another color from which the associated component will be extracted.

### Methods

<< == === a a= alpha alpha= alpha_blend alpha_blend! b b= blue blue= eql? from_palette? g g= green green= new opaque? r r= red red= to_s transparent?

### Constants

BLACK | = | Color[0.0, 0.0, 0.0].freeze
WHITE | = | Color[1.0, 1.0, 1.0].freeze
TRANSPARENT | = | Color[0.0, 0.0, 0.0, ALPHA_TRANSPARENT].freeze

### External Aliases

rgba | -> | to_i
new | -> | []

### Attributes

index | [R] | The palette index of this color, if associated with an image palette
palette | [R] | The palette of this color, if associated with an image palette

### Public Class methods

new(r, g, b, a = ALPHA_OPAQUE)

Create a new Color object with the given component values.

### Public Instance methods

<<(other)

Alias for alpha_blend!

==(other)

Compare this color with another color. Returns true if the associated red, green, blue, and alpha components are identical.

===(other)

Return true if this color is visually identical to another color.

a()

Alias for alpha

a=(value)

Alias for alpha=

alpha()

Return the alpha component of this color (0..ALPHA_MAX).

alpha=(value)

Modify the alpha component of this color. If this color is associated with a palette entry, this also modifies the palette.

alpha_blend(other)

Like Color#alpha_blend! except returns a new Color without modifying the receiver.

alpha_blend!(other)

Alpha blend this color with the given color. If this color is associated with a palette entry, this also modifies the palette.

b()

Alias for blue

b=(value)

Alias for blue=

blue()

Return the blue component of this color (0..RGB_MAX).

blue=(value)

Modify the blue component of this color. If this color is associated with a palette entry, this also modifies the palette.

eql?(other)

Compare this color with another color in a manner that takes into account palette identities.

from_palette?(palette = nil)

Return true if this color is associated with the specified palette, or with any palette if nil is given.

g()

Alias for green

g=(value)

Alias for green=

green()

Return the green component of this color (0..RGB_MAX).

green=(value)

Modify the green component of this color. If this color is associated with a palette entry, this also modifies the palette.

opaque?()

Return true if the alpha channel of this color is completely opaque.

r()

Alias for red

r=(value)

Alias for red=

red()

Return the red component of this color (0..RGB_MAX).

red=(value)

Modify the red component of this color. If this color is associated with a palette entry, this also modifies the palette.

to_s()

Return a string description of this color.

transparent?()

Return true if the alpha channel of this color is completely transparent.

[Validate]