# module Cairo::Color

### Constants

ALICE_BLUE

  Alice Blue: #F0F8FF

ALIZARIN_CRIMSON

  Alizarin Crimson: #E32636

AMARANTH

  Amaranth: #E52B50

AMBER

  Amber: #FFBF00

AMETHYST

  Amethyst: #9966CC

APRICOT

  Apricot: #FBCEB1

AQUA

  Aqua: #00FFFF

AQUAMARINE

  Aquamarine: #7FFFD4

ASPARAGUS

  Asparagus: #7BA05B

AZURE

  Azure: #007FFF

BEIGE

  Beige: #F5F5DC

BISTRE

  Bistre: #3D2B1F

BLACK

  Black: #000000

BLAZE_ORANGE
BLUE

  Blue: #0000FF

BONDI_BLUE

  Bondi Blue: #0095B6

BRIGHT_GREEN

  Bright green: #66FF00

BRIGHT_TURQUOISE

  Bright turquoise: #08E8DE

BROWN

  Brown: #964B00

BUFF

  Buff: #F0DC82

BURGUNDY

  Burgundy: #900020

BURNT_ORANGE

  Burnt Orange: #CC5500

BURNT_SIENNA

  Burnt Sienna: #E97451

BURNT_UMBER

  Burnt umber: #8A3324

CAMOUFLAGE_GREEN

  Camouflage green: #78866B

CARDINAL

  Cardinal: #C41E3A

CARMINE

  Carmine: #960018

CARNATION

  Carnation: #F95A61

CARROT_ORANGE

  Carrot orange: #ED9121

CELADON

  Celadon: #ACE1AF

CERISE

  Cerise: #DE3163

CERULEAN

  Cerulean: #007BA7

CERULEAN_BLUE

  Cerulean blue: #2A52BE

CHARTREUSE

  Chartreuse: #7FFF00

CHARTREUSE_YELLOW

  Chartreuse yellow: #DFFF00

CHESTNUT

  Chestnut: #CD5C5C

CHOCOLATE

  Chocolate: #D2691E

CINNAMON

  Cinnamon: #7B3F00

COBALT

  Cobalt: #0047AB

COPPER

  Copper: #B87333

COPPER_ROSE

  Copper rose: #996666

CORAL

  Coral: #FF7F50

CORAL_RED

  Coral Red: #FF4040

CORN

  Corn: #FBEC5D

CORNFLOWER_BLUE

  Cornflower blue: #6495ED

CREAM

  Cream: #FFFDD0

CRIMSON

  Crimson: #DC143C

CYAN

  Cyan: #00FFFF

DARK_BLUE

  Dark blue: #0000C8

DARK_POWDER_BLUE
DENIM

  Denim: #1560BD

DODGER_BLUE

  Dodger blue: #1E90FF

EGGPLANT

  Eggplant: #990066

EMERALD

  Emerald: #50C878

FALU_RED

  Falu red: #801818

FERN_GREEN

  Fern green: #4F7942

FLAX

  Flax: #EEDC82

FOREST_GREEN

  Forest green: #228B22

FRENCH_ROSE

  French Rose: #F64A8A

FUCHSIA

  Fuchsia: #FF00FF

GAMBOGE

  Gamboge: #E49B0F

GOLD

  Gold: #FFD700

GOLDENROD

  Goldenrod: #DAA520

GRAY

  Gray: #808080

GRAY_ASPARAGUS

  Gray-asparagus: #465945

GREEN

  Green: #00FF00

GREEN_YELLOW

  Green-yellow: #ADFF2F

HARLEQUIN

  Harlequin: #3FFF00

HELIOTROPE

  Heliotrope: #DF73FF

HEX_RE
HOLLYWOOD_CERISE

  Hollywood Cerise: #F400A1

HOT_MAGENTA

  Hot Magenta: #FF00CC

HOT_PINK

  Hot Pink: #FF69B4

INDIGO

  Indigo: #4B0082

INTERNATIONAL_KLEIN_BLUE

  International Klein Blue: #002FA7

INTERNATIONAL_ORANGE

  International orange: #FF4F00

IVORY

  Ivory: #FFFFF0

JADE

  Jade: #00A86B

KHAKI

  Khaki: #C3B091

KHAKI_X11

  Khaki (X11): #F0E68C

LAVENDER

  Lavender: #B57EDC

LAVENDER_BLUE

  Lavender blue: #CCCCFF

LAVENDER_BLUSH

  Lavender blush: #FFF0F5

LAVENDER_GRAY

  Lavender gray: #BDBBD7

LAVENDER_PINK

  Lavender pink: #FBAED2

LAVENDER_ROSE

  Lavender rose: #FBA0E3

LEMON

  Lemon: #FDE910

LEMON_CHIFFON

  Lemon chiffon: #FFFACD

LILAC

  Lilac: #C8A2C8

LIME

  Lime: #BFFF00

LINEN

  Linen: #FAF0E6

MAGENTA

  Magenta: #FF00FF

MALACHITE

  Malachite: #0BDA51

MAROON

  Maroon: #800000

MAUVE

  Mauve: #E0B0FF

MEDIUM_CARMINE

  Medium carmine: #AF4035

MEDIUM_LAVENDER

  Medium Lavender: #EE82EE

MEDIUM_PURPLE

  Medium Purple: #9370DB

MIDNIGHT_BLUE

  Midnight Blue: #003366

MINT_GREEN

  Mint Green: #98FF98

MOSS_GREEN

  Moss green: #ADDFAD

MOUNTBATTEN_PINK

  Mountbatten pink: #997A8D

MUSTARD

  Mustard: #FFDB58

NAVAJO_WHITE

  Navajo white: #FFDEAD

NAVY_BLUE

  Navy Blue: #000080

OCHRE

  Ochre: #CC7722

OLD_GOLD

  Old Gold: #CFB53B

OLD_LACE

  Old Lace: #FDF5E6

OLD_LAVENDER

  Old Lavender: #796878

OLD_ROSE

  Old Rose: #C08081

OLIVE

  Olive: #808000

OLIVE_DRAB

  Olive Drab: #6B8E23

ORANGE
ORANGE_COLOR_WHEEL

  Orange (color wheel): #FF7500

ORANGE_PEEL

  Orange Peel: #FFA000

ORANGE_WEB

  Orange (web): #FFA500

ORCHID

  Orchid: #DA70D6

PAPAYA_WHIP

  Papaya whip: #FFEFD5

PASTEL_GREEN

  Pastel green: #77DD77

PASTEL_PINK

  Pastel pink: #FFD1DC

PEACH

  Peach: #FFE5B4

PEACH_ORANGE

  Peach-orange: #FFCC99

PEACH_YELLOW

  Peach-yellow: #FADFAD

PEAR

  Pear: #D1E231

PERIWINKLE

  Periwinkle: #CCCCFF

PERSIAN_BLUE

  Persian blue: #1C39BB

PERSIAN_GREEN

  Persian green: #00A693

PERSIAN_INDIGO

  Persian indigo: #32127A

PERSIAN_PINK

  Persian pink: #F77FBE

PERSIAN_RED

  Persian red: #CC3333

PERSIAN_ROSE

  Persian rose: #FF1CB1

PINE_GREEN

  Pine Green: #01796F

PINK

  Pink: #FFC0CB

PINK_ORANGE

  Pink-orange: #FF9966

POMEGRANATE

  Pomegranate: #F34723

POWDER_BLUE_WEB

  Powder blue (web): #B0E0E6

PRUSSIAN_BLUE

  Prussian blue: #003153

PUCE

  Puce: #CC8899

PUMPKIN

  Pumpkin: #FF7518

PURPLE

  Purple: #660099

RAW_UMBER

  Raw umber: #734A12

RED

  Red: #FF0000

RED_VIOLET

  Red-violet: #C71585

ROBIN_EGG_BLUE

  Robin egg blue: #00CCCC

ROSE

  Rose: #FF007F

ROYAL_BLUE

  Royal Blue: #4169E1

RUSSET

  Russet: #80461B

RUST

  Rust: #B7410E

SAFETY_ORANGE

  Safety Orange (Blaze Orange): #FF6600

SAFFRON

  Saffron: #F4C430

SALMON

  Salmon: #FF8C69

SANDY_BROWN

  Sandy brown: #F4A460

SANGRIA

  Sangria: #92000A

SAPPHIRE

  Sapphire: #082567

SCARLET

  Scarlet: #FF2400

SCHOOL_BUS_YELLOW

  School bus yellow: #FFD800

SEASHELL

  Seashell: #FFF5EE

SEA_GREEN

  Sea Green: #2E8B57

SELECTIVE_YELLOW

  Selective yellow: #FFBA00

SEPIA

  Sepia: #704214

SHOCKING_PINK

  Shocking Pink: #FC0FC0

SILVER

  Silver: #C0C0C0

SLATE_GRAY

  Slate gray: #708090

SMALT

  Smalt (Dark powder blue): #003399

SPRING_GREEN

  Spring Green: #00FF7F

STEEL_BLUE

  Steel blue: #4682B4

SWAMP_GREEN

  Swamp green: #ACB78E

TAN

  Tan: #D2B48C

TANGERINE

  Tangerine: #FFCC00

TAUPE

  Taupe: #483C32

TAWNY
TEAL

  Teal: #008080

TEA_GREEN

  Tea Green: #D0F0C0

TENNE

  Tenn&eacute; (Tawny): #CD5700

TERRA_COTTA

  Terra cotta: #E2725B

THISTLE

  Thistle: #D8BFD8

TURQUOISE

  Turquoise: #30D5C8

ULTRAMARINE

  Ultramarine: #120A8F

VERMILION

  Vermilion: #FF4D00

VIOLET

  Violet: #8B00FF

VIOLET_EGGPLANT

  Violet-eggplant: #991199

VIRIDIAN

  Viridian: #40826D

WHEAT

  Wheat: #F5DEB3

WHITE

  White: #FFFFFF

WISTERIA

  Wisteria: #C9A0DC

YELLOW

  Yellow: #FFFF00

ZINNWALDITE

  Zinnwaldite: #EBC2AF

### Public Instance Methods

parse(value, robust=false) click to toggle source

    # File lib/cairo/color.rb, line 4
    def parse(value, robust=false)
      return value.dup if value.is_a?(Base)
      case value
      when Array
        case value.first
        when :cmyk, :cmyka
          CMYK.new(*value[1..-1])
        when :hsv, :hsva
          HSV.new(*value[1..-1])
        else
          _, *value = value if [:rgb, :rgba].include?(value.first)
          RGB.new(*value)
        end
      when /\A#/ #
        parse_hex_color(value)
      when String, Symbol
        name = Cairo.normalize_const_name(value)
        begin
          const_get(name).dup
        rescue NameError
          raise ArgumentError, "unknown color name: #{value}"
        end
      else
        if robust
          raise ArgumentError, "can't parse as color name: #{value.inspect}"
        end
        value
      end
    end

parse_hex_color(value) click to toggle source

    # File lib/cairo/color.rb, line 35
    def parse_hex_color(value)
      case value
      when /\A#((?:#{HEX_RE}){3,4})\z/ #
        RGB.new(*$1.scan(/./).collect {|part| part.hex / 15.0})
      when /\A#((?:#{HEX_RE}{2,2}){3,4})\z/ #
        RGB.new(*$1.scan(/.{2,2}/).collect {|part| part.hex / 255.0})
      when /\A#((?:#{HEX_RE}{4,4}){3,4})\z/ #
        RGB.new(*$1.scan(/.{4,4}/).collect {|part| part.hex / 65535.0})
      else
        message = "invalid hex color format: #{value} should be "
        message << "#RGB, #RGBA, #RRGGBB, #RRGGBBAA, #RRRRGGGGBBBB "
        message << "or #RRRRGGGGBBBBAAAA"
        raise ArgumentError, message
      end
    end