Class: Color::GrayScale

Class | Color::GrayScale
In: | lib/color.rb lib/color/grayscale.rb
Parent: | Object

A colour object representing shades of grey. Used primarily in PDF document creation.

### Methods

+ - == brightness css_hsl css_hsla css_rgb css_rgba darken_by from_fraction from_percent g g= gray gray= grey grey= html inspect lighten_by new pdf_fill pdf_stroke to_cmyk to_grayscale to_greyscale to_hsl to_rgb to_yiq

### Constants

PDF_FORMAT_STR | = | "%.3f %s" |  | The format of a DeviceGrey colour for PDF. In color-tools 2.0 this will be removed from this package and added back as a modification by the PDF::Writer package.

### Public Class methods

from_fraction(g = 0)

Creates a greyscale colour object from fractional values 0..1.

      Color::GreyScale.from_fraction(0.5)

from_percent(g = 0)

Creates a greyscale colour object from percentages 0..100.

      Color::GrayScale.from_percent(50)

new(g = 0)

Creates a greyscale colour object from percentages 0..100.

      Color::GrayScale.new(50)

### Public Instance methods

+(other)

Adds another colour to the current colour. The other colour will be converted to grayscale before addition. This conversion depends upon a to_grayscale method on the other colour.

The addition is done using the grayscale accessor methods to ensure a valid colour in the result.

-(other)

Subtracts another colour to the current colour. The other colour will be converted to grayscale before subtraction. This conversion depends upon a to_grayscale method on the other colour.

The subtraction is done using the grayscale accessor methods to ensure a valid colour in the result.

==(other)

Compares the other colour to this one. The other colour will be converted to GreyScale before comparison, so the comparison between a GreyScale colour and a non-GreyScale colour will be approximate and based on the other colour‘s to_greyscale conversion. If there is no to_greyscale conversion, this will raise an exception. This will report that two GreyScale values are equivalent if they are within COLOR_TOLERANCE of each other.

brightness()

Returns the brightness value for this greyscale value; this is the greyscale value itself.

css_hsl()

Present the colour as an HSL HTML/CSS colour string (e.g., "hsl(180, 25%, 35%)"). Note that this will perform a to_hsl operation.

css_hsla()

Present the colour as an HSLA (with alpha) HTML/CSS colour string (e.g., "hsla(180, 25%, 35%, 1)"). Note that this will perform a to_hsl operation.

css_rgb()

Present the colour as an RGB HTML/CSS colour string (e.g., "rgb(0%, 50%, 100%)").

css_rgba()

Present the colour as an RGBA (with alpha) HTML/CSS colour string (e.g., "rgb(0%, 50%, 100%, 1)").

darken_by(percent)

Darken the greyscale colour by the stated percent.

g()

Returns the grayscale value as a fractional value of white in the range 0.0 .. 1.0.

g=(gg)

Returns the grayscale value as a fractional value of white in the range 0.0 .. 1.0.

gray()

Returns the grayscale value as a percentage of white (100% gray is white).

gray=(gg)

Sets the grayscale value as a percentage of white.

grey()

Alias for gray

grey=(gg)

Alias for gray=

html()

Present the colour as an HTML/CSS colour string.

inspect()
lighten_by(percent)

Lightens the greyscale colour by the stated percent.

pdf_fill()

Present the colour as a DeviceGrey fill colour string for PDF. This will be removed from the default package in color-tools 2.0.

pdf_stroke()

Present the colour as a DeviceGrey stroke colour string for PDF. This will be removed from the default package in color-tools 2.0.

to_cmyk()

Convert the greyscale colour to CMYK.

to_grayscale()

Reflexive conversion.

to_greyscale()

Alias for to_grayscale

to_hsl()

Returns the HSL colour encoding of the greyscale value.

to_rgb(ignored = true)

Convert the greyscale colour to RGB.

to_yiq()

Returns the YIQ (NTSC) colour encoding of the greyscale value. This is an approximation, as the values for I and Q are calculated by treating the greyscale value as an RGB value. The Y (intensity or brightness) value is the same as the greyscale value.

[Validate]