Class: Color

Inherits:
Object
  • Object
show all
Defined in:
lib/color.rb

Overview

Color components grouped into a single object. Colors consist of red, green, blue, and alpha. Each color component uses a floating-point value and is restricted to the range 0 to 255.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Color) initialize(red = 0, green = 0, blue = 0, alpha = 0) - (Color) initialize(red, green, blue, alpha = 255)

Creates the color object and sets the initial values.

Overloads:

  • - (Color) initialize(red = 0, green = 0, blue = 0, alpha = 0)

    Initializes all components (including alpha) to 0.

  • - (Color) initialize(red, green, blue, alpha = 255)

    Initializes the color components to the specified values.

    Parameters:

    • red (Float)

      Value of the red component - 0 to 255.

    • green (Float)

      Value of the green component - 0 to 255.

    • blue (Float)

      Value of the blue component - 0 to 255.

    • alpha (Float) (defaults to: 255)

      Value of the alpha component - 0 to 255. 0 is completely transparent and 255 is fully opaque.



17
18
19
# File 'lib/color.rb', line 17

def initialize(*args)
  fail NotImplementedError
end

Instance Attribute Details

- (Float) alpha

Value of the alpha component from 0 to 255. 0 is completely transparent and 255 is fully opaque. Out of range values are automatically corrected.

Returns:

  • (Float)


56
57
58
# File 'lib/color.rb', line 56

def alpha
  @alpha
end

- (Float) blue

Value of the blue component from 0 to 255. Out of range values are automatically corrected.

Returns:

  • (Float)


50
51
52
# File 'lib/color.rb', line 50

def blue
  @blue
end

- (Float) green

Value of the green component from 0 to 255. Out of range values are automatically corrected.

Returns:

  • (Float)


45
46
47
# File 'lib/color.rb', line 45

def green
  @green
end

- (Float) red

Value of the red component from 0 to 255. Out of range values are automatically corrected.

Returns:

  • (Float)


40
41
42
# File 'lib/color.rb', line 40

def red
  @red
end

Instance Method Details

- (self) set(red, green, blue, alpha = 255) - (self) set(color)

Sets all components at once.

Overloads:

  • - (self) set(red, green, blue, alpha = 255)

    Sets all of the color components to the specified values.

    Parameters:

    • red (Float)

      Value of the red component - 0 to 255.

    • green (Float)

      Value of the green component - 0 to 255.

    • blue (Float)

      Value of the blue component - 0 to 255.

    • alpha (Float) (defaults to: 255)

      Value of the alpha component - 0 to 255. 0 is completely transparent and 255 is fully opaque.

  • - (self) set(color)

    Copies the component values from another color.

    Parameters:

    • color (Color)

      Color to copy component values from.

Returns:

  • (self)


33
34
35
# File 'lib/color.rb', line 33

def set(*args)
  fail NotImplementedError
end