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

Create a new Color object with the given component values.

Public Instance methods

<<(other)

Alias for alpha_blend!

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

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

a()

Alias for alpha

a=(value)

Alias for alpha=

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

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

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

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=

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

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

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

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=

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

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

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

r()

Alias for red

r=(value)

Alias for red=

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

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

Return a string description of this color.

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

[Validate]