class TaskJuggler::Painter::Color

A description of the color. The color is stored internally as an RGB value. Common names are provided for many popular colors.

Constants

NamedColors

Public Class Methods

new(*args) click to toggle source

Create a new Color object.

# File lib/taskjuggler/Painter/Color.rb, line 172
def initialize(*args)
  if args.length == 1
    unless NamedColors.include?(args[0])
      raise "Unknown color name #{args[0]}"
    end

    @r, @g, @b = NamedColors[args[0]]
  elsif args.length == 3
    args.each do |v|
      unless v >= 0 && v < 256
        raise ArgumentError, "RGB values (#{args.join(', ')}) must " +
                             "be between 0 and 255."
      end
    end

    @r, @g, @b = args
  elsif args.length == 4
    unless args[0] >= 0 && args[0] < 360
      raise ArgumentError, "Hue value must be between 0 and 360"
    end
    unless args[1] >= 0 && args[1] <= 255
      raise ArgumentError, "Saturation value (#{args[1]}) must be " +
                           "between 0 and 255"
    end
    unless args[2] >= 0 && args[2] <= 255
      raise ArgumentError, "Color value (#{args[2]}) must be " +
                           "between 0 and 255"
    end
    @r, @g, @b = hsvToRgb(*args[0..2])
  else
    raise ArgumentError
  end
end

Public Instance Methods

to_hsv() click to toggle source
# File lib/taskjuggler/Painter/Color.rb, line 210
def to_hsv
  rgbToHsv(@r, @g, @b)
end
to_rgb() click to toggle source
# File lib/taskjuggler/Painter/Color.rb, line 206
def to_rgb
  [ @r, @g, @b ]
end
to_s() click to toggle source

Convert the RGB value into a String format that is used in HTML.

# File lib/taskjuggler/Painter/Color.rb, line 215
def to_s
  format("#%02x%02x%02x", @r, @g, @b)
end