Module: Cairo::Color

Includes:
X11
Included in:
Context
Defined in:
lib/cairo/color.rb,
lib/cairo/colors.rb

Defined Under Namespace

Modules: X11 Classes: Base, CMYK, HSV, RGB

Constant Summary collapse

HEX_RE =
"(?i:[a-f\\d])"
ALICE_BLUE =

Alice Blue: #F0F8FF

RGB.new(0.941176470588235, 0.972549019607843, 1.0)
ALIZARIN_CRIMSON =

Alizarin Crimson: #E32636

RGB.new(0.890196078431372, 0.149019607843137, 0.211764705882353)
AMARANTH =

Amaranth: #E52B50

RGB.new(0.898039215686275, 0.168627450980392, 0.313725490196078)
AMBER =

Amber: #FFBF00

RGB.new(1.0, 0.749019607843137, 0.0)
AMETHYST =

Amethyst: #9966CC

RGB.new(0.6, 0.4, 0.8)
APRICOT =

Apricot: #FBCEB1

RGB.new(0.984313725490196, 0.807843137254902, 0.694117647058824)
AQUA =

Aqua: #00FFFF

RGB.new(0.0, 1.0, 1.0)
AQUAMARINE =

Aquamarine: #7FFFD4

RGB.new(0.498039215686275, 1.0, 0.831372549019608)
ASPARAGUS =

Asparagus: #7BA05B

RGB.new(0.482352941176471, 0.627450980392157, 0.356862745098039)
AZURE =

Azure: #007FFF

RGB.new(0.0, 0.498039215686275, 1.0)
BEIGE =

Beige: #F5F5DC

RGB.new(0.96078431372549, 0.96078431372549, 0.862745098039216)
BISTRE =

Bistre: #3D2B1F

RGB.new(0.23921568627451, 0.168627450980392, 0.12156862745098)
BLACK =

Black: #000000

RGB.new(0.0, 0.0, 0.0)
BLUE =

Blue: #0000FF

RGB.new(0.0, 0.0, 1.0)
BONDI_BLUE =

Bondi Blue: #0095B6

RGB.new(0.0, 0.584313725490196, 0.713725490196078)
BRIGHT_GREEN =

Bright green: #66FF00

RGB.new(0.4, 1.0, 0.0)
BRIGHT_TURQUOISE =

Bright turquoise: #08E8DE

RGB.new(0.0313725490196078, 0.909803921568627, 0.870588235294118)
BROWN =

Brown: #964B00

RGB.new(0.588235294117647, 0.294117647058824, 0.0)
BUFF =

Buff: #F0DC82

RGB.new(0.941176470588235, 0.862745098039216, 0.509803921568627)
BURGUNDY =

Burgundy: #900020

RGB.new(0.501960784313725, 0.0, 0.125490196078431)
BURNT_ORANGE =

Burnt Orange: #CC5500

RGB.new(0.8, 0.333333333333333, 0.0)
BURNT_SIENNA =

Burnt Sienna: #E97451

RGB.new(0.913725490196078, 0.454901960784314, 0.317647058823529)
BURNT_UMBER =

Burnt umber: #8A3324

RGB.new(0.541176470588235, 0.2, 0.141176470588235)
CAMOUFLAGE_GREEN =

Camouflage green: #78866B

RGB.new(0.470588235294118, 0.525490196078431, 0.419607843137255)
CARDINAL =

Cardinal: #C41E3A

RGB.new(0.768627450980392, 0.117647058823529, 0.227450980392157)
CARMINE =

Carmine: #960018

RGB.new(0.588235294117647, 0.0, 0.0941176470588235)
CARNATION =

Carnation: #F95A61

RGB.new(0.976470588235294, 0.352941176470588, 0.380392156862745)
CARROT_ORANGE =

Carrot orange: #ED9121

RGB.new(0.929411764705882, 0.568627450980392, 0.129411764705882)
CELADON =

Celadon: #ACE1AF

RGB.new(0.674509803921569, 0.882352941176471, 0.686274509803922)
CERISE =

Cerise: #DE3163

RGB.new(0.870588235294118, 0.192156862745098, 0.388235294117647)
CERULEAN =

Cerulean: #007BA7

RGB.new(0.0, 0.482352941176471, 0.654901960784314)
CERULEAN_BLUE =

Cerulean blue: #2A52BE

RGB.new(0.164705882352941, 0.32156862745098, 0.745098039215686)
CHARTREUSE =

Chartreuse: #7FFF00

RGB.new(0.498039215686275, 1.0, 0.0)
CHARTREUSE_YELLOW =

Chartreuse yellow: #DFFF00

RGB.new(0.874509803921569, 1.0, 0.0)
CHESTNUT =

Chestnut: #CD5C5C

RGB.new(0.803921568627451, 0.36078431372549, 0.36078431372549)
CHOCOLATE =

Chocolate: #D2691E

RGB.new(0.823529411764706, 0.411764705882353, 0.117647058823529)
CINNAMON =

Cinnamon: #7B3F00

RGB.new(0.482352941176471, 0.247058823529412, 0.0)
COBALT =

Cobalt: #0047AB

RGB.new(0.0, 0.27843137254902, 0.670588235294118)
COPPER =

Copper: #B87333

RGB.new(0.72156862745098, 0.450980392156863, 0.2)
COPPER_ROSE =

Copper rose: #996666

RGB.new(0.6, 0.4, 0.4)
CORAL =

Coral: #FF7F50

RGB.new(1.0, 0.498039215686275, 0.313725490196078)
CORAL_RED =

Coral Red: #FF4040

RGB.new(1.0, 0.250980392156863, 0.250980392156863)
CORN =

Corn: #FBEC5D

RGB.new(0.984313725490196, 0.925490196078431, 0.364705882352941)
CORNFLOWER_BLUE =

Cornflower blue: #6495ED

RGB.new(0.392156862745098, 0.584313725490196, 0.929411764705882)
CREAM =

Cream: #FFFDD0

RGB.new(1.0, 0.992156862745098, 0.815686274509804)
CRIMSON =

Crimson: #DC143C

RGB.new(0.862745098039216, 0.0784313725490196, 0.235294117647059)
CYAN =

Cyan: #00FFFF

RGB.new(0.0, 1.0, 1.0)
DARK_BLUE =

Dark blue: #0000C8

RGB.new(0.0, 0.0, 0.545098039215686)
DENIM =

Denim: #1560BD

RGB.new(0.0823529411764706, 0.376470588235294, 0.741176470588235)
DODGER_BLUE =

Dodger blue: #1E90FF

RGB.new(0.117647058823529, 0.564705882352941, 1.0)
EMERALD =

Emerald: #50C878

RGB.new(0.313725490196078, 0.784313725490196, 0.470588235294118)
EGGPLANT =

Eggplant: #990066

RGB.new(0.6, 0.0, 0.4)
FALU_RED =

Falu red: #801818

RGB.new(0.501960784313725, 0.0941176470588235, 0.0941176470588235)
FERN_GREEN =

Fern green: #4F7942

RGB.new(0.309803921568627, 0.474509803921569, 0.258823529411765)
FLAX =

Flax: #EEDC82

RGB.new(0.933333333333333, 0.862745098039216, 0.509803921568627)
FOREST_GREEN =

Forest green: #228B22

RGB.new(0.133333333333333, 0.545098039215686, 0.133333333333333)
FRENCH_ROSE =

French Rose: #F64A8A

RGB.new(0.964705882352941, 0.290196078431373, 0.541176470588235)
FUCHSIA =

Fuchsia: #FF00FF

RGB.new(1.0, 0.0, 1.0)
GAMBOGE =

Gamboge: #E49B0F

RGB.new(0.894117647058824, 0.607843137254902, 0.0588235294117647)
GOLD =

Gold: #FFD700

RGB.new(1.0, 0.843137254901961, 0.0)
GOLDENROD =

Goldenrod: #DAA520

RGB.new(0.854901960784314, 0.647058823529412, 0.125490196078431)
GRAY =

Gray: #808080

RGB.new(0.501960784313725, 0.501960784313725, 0.501960784313725)
GRAY_ASPARAGUS =

Gray-asparagus: #465945

RGB.new(0.274509803921569, 0.349019607843137, 0.270588235294118)
GREEN =

Green: #00FF00

RGB.new(0.0, 1.0, 0.0)
GREEN_YELLOW =

Green-yellow: #ADFF2F

RGB.new(0.67843137254902, 1.0, 0.184313725490196)
HARLEQUIN =

Harlequin: #3FFF00

RGB.new(0.247058823529412, 1.0, 0.0)
HELIOTROPE =

Heliotrope: #DF73FF

RGB.new(0.874509803921569, 0.450980392156863, 1.0)
HOLLYWOOD_CERISE =

Hollywood Cerise: #F400A1

RGB.new(0.956862745098039, 0.0, 0.631372549019608)
HOT_MAGENTA =

Hot Magenta: #FF00CC

RGB.new(1.0, 0.0, 0.8)
HOT_PINK =

Hot Pink: #FF69B4

RGB.new(1.0, 0.411764705882353, 0.705882352941177)
INDIGO =

Indigo: #4B0082

RGB.new(0.294117647058824, 0.0, 0.509803921568627)
INTERNATIONAL_KLEIN_BLUE =

International Klein Blue: #002FA7

RGB.new(0.0, 0.184313725490196, 0.654901960784314)
INTERNATIONAL_ORANGE =

International orange: #FF4F00

RGB.new(1.0, 0.309803921568627, 0.0)
IVORY =

Ivory: #FFFFF0

RGB.new(1.0, 1.0, 0.941176470588235)
JADE =

Jade: #00A86B

RGB.new(0.0, 0.658823529411765, 0.419607843137255)
KHAKI =

Khaki: #C3B091

RGB.new(0.764705882352941, 0.690196078431373, 0.568627450980392)
KHAKI_X11 =

Khaki (X11): #F0E68C

RGB.new(0.941176470588235, 0.901960784313726, 0.549019607843137)
LAVENDER =

Lavender: #B57EDC

RGB.new(0.709803921568627, 0.494117647058824, 0.862745098039216)
LAVENDER_BLUE =

Lavender blue: #CCCCFF

RGB.new(0.8, 0.8, 1.0)
LAVENDER_BLUSH =

Lavender blush: #FFF0F5

RGB.new(1.0, 0.941176470588235, 0.96078431372549)
LAVENDER_GRAY =

Lavender gray: #BDBBD7

RGB.new(0.741176470588235, 0.733333333333333, 0.843137254901961)
LAVENDER_PINK =

Lavender pink: #FBAED2

RGB.new(0.984313725490196, 0.682352941176471, 0.823529411764706)
LAVENDER_ROSE =

Lavender rose: #FBA0E3

RGB.new(0.984313725490196, 0.627450980392157, 0.890196078431372)
LEMON =

Lemon: #FDE910

RGB.new(0.992156862745098, 0.913725490196078, 0.0627450980392157)
LEMON_CHIFFON =

Lemon chiffon: #FFFACD

RGB.new(1.0, 0.980392156862745, 0.803921568627451)
LILAC =

Lilac: #C8A2C8

RGB.new(0.784313725490196, 0.635294117647059, 0.784313725490196)
LIME =

Lime: #BFFF00

RGB.new(0.749019607843137, 1.0, 0.0)
LINEN =

Linen: #FAF0E6

RGB.new(0.980392156862745, 0.941176470588235, 0.901960784313726)
MAGENTA =

Magenta: #FF00FF

RGB.new(1.0, 0.0, 1.0)
MALACHITE =

Malachite: #0BDA51

RGB.new(0.0431372549019608, 0.854901960784314, 0.317647058823529)
MAROON =

Maroon: #800000

RGB.new(0.501960784313725, 0.0, 0.0)
MAUVE =

Mauve: #E0B0FF

RGB.new(0.87843137254902, 0.690196078431373, 1.0)
MEDIUM_CARMINE =

Medium carmine: #AF4035

RGB.new(0.686274509803922, 0.250980392156863, 0.207843137254902)
MEDIUM_LAVENDER =

Medium Lavender: #EE82EE

RGB.new(0.933333333333333, 0.509803921568627, 0.933333333333333)
MEDIUM_PURPLE =

Medium Purple: #9370DB

RGB.new(0.576470588235294, 0.43921568627451, 0.858823529411765)
MIDNIGHT_BLUE =

Midnight Blue: #003366

RGB.new(0.0, 0.2, 0.4)
MINT_GREEN =

Mint Green: #98FF98

RGB.new(0.596078431372549, 1.0, 0.596078431372549)
MOSS_GREEN =

Moss green: #ADDFAD

RGB.new(0.67843137254902, 0.874509803921569, 0.67843137254902)
MOUNTBATTEN_PINK =

Mountbatten pink: #997A8D

RGB.new(0.6, 0.47843137254902, 0.552941176470588)
MUSTARD =

Mustard: #FFDB58

RGB.new(1.0, 0.858823529411765, 0.345098039215686)
RGB.new(1.0, 0.870588235294118, 0.67843137254902)
RGB.new(0.0, 0.0, 0.501960784313725)
OCHRE =

Ochre: #CC7722

RGB.new(0.8, 0.466666666666667, 0.133333333333333)
OLD_GOLD =

Old Gold: #CFB53B

RGB.new(0.811764705882353, 0.709803921568627, 0.231372549019608)
OLD_LACE =

Old Lace: #FDF5E6

RGB.new(0.992156862745098, 0.96078431372549, 0.901960784313726)
OLD_LAVENDER =

Old Lavender: #796878

RGB.new(0.474509803921569, 0.407843137254902, 0.470588235294118)
OLD_ROSE =

Old Rose: #C08081

RGB.new(0.752941176470588, 0.501960784313725, 0.505882352941176)
OLIVE =

Olive: #808000

RGB.new(0.501960784313725, 0.501960784313725, 0.0)
OLIVE_DRAB =

Olive Drab: #6B8E23

RGB.new(0.419607843137255, 0.556862745098039, 0.137254901960784)
ORANGE_COLOR_WHEEL =

Orange (color wheel): #FF7500

RGB.new(1.0, 0.498039215686275, 0.0)
ORANGE =
ORANGE_COLOR_WHEEL
ORANGE_WEB =

Orange (web): #FFA500

RGB.new(1.0, 0.647058823529412, 0.0)
ORANGE_PEEL =

Orange Peel: #FFA000

RGB.new(1.0, 0.627450980392157, 0.0)
ORCHID =

Orchid: #DA70D6

RGB.new(0.854901960784314, 0.43921568627451, 0.83921568627451)
PAPAYA_WHIP =

Papaya whip: #FFEFD5

RGB.new(1.0, 0.937254901960784, 0.835294117647059)
PASTEL_GREEN =

Pastel green: #77DD77

RGB.new(0.466666666666667, 0.866666666666667, 0.466666666666667)
PASTEL_PINK =

Pastel pink: #FFD1DC

RGB.new(1.0, 0.819607843137255, 0.862745098039216)
PEACH =

Peach: #FFE5B4

RGB.new(1.0, 0.898039215686275, 0.705882352941177)
PEACH_ORANGE =

Peach-orange: #FFCC99

RGB.new(1.0, 0.8, 0.6)
PEACH_YELLOW =

Peach-yellow: #FADFAD

RGB.new(0.980392156862745, 0.874509803921569, 0.67843137254902)
PEAR =

Pear: #D1E231

RGB.new(0.819607843137255, 0.886274509803922, 0.192156862745098)
PERIWINKLE =

Periwinkle: #CCCCFF

RGB.new(0.8, 0.8, 1.0)
PERSIAN_BLUE =

Persian blue: #1C39BB

RGB.new(0.109803921568627, 0.223529411764706, 0.733333333333333)
PERSIAN_GREEN =

Persian green: #00A693

RGB.new(0.0, 0.650980392156863, 0.576470588235294)
PERSIAN_INDIGO =

Persian indigo: #32127A

RGB.new(0.196078431372549, 0.0705882352941176, 0.47843137254902)
PERSIAN_PINK =

Persian pink: #F77FBE

RGB.new(0.968627450980392, 0.498039215686275, 0.745098039215686)
PERSIAN_RED =

Persian red: #CC3333

RGB.new(0.8, 0.2, 0.2)
PERSIAN_ROSE =

Persian rose: #FF1CB1

RGB.new(1.0, 0.109803921568627, 0.694117647058824)
PINE_GREEN =

Pine Green: #01796F

RGB.new(0.00392156862745098, 0.474509803921569, 0.435294117647059)
PINK =

Pink: #FFC0CB

RGB.new(1.0, 0.752941176470588, 0.796078431372549)
PINK_ORANGE =

Pink-orange: #FF9966

RGB.new(1.0, 0.6, 0.4)
POMEGRANATE =

Pomegranate: #F34723

RGB.new(0.952941176470588, 0.27843137254902, 0.137254901960784)
POWDER_BLUE_WEB =

Powder blue (web): #B0E0E6

RGB.new(0.690196078431373, 0.87843137254902, 0.901960784313726)
PUCE =

Puce: #CC8899

RGB.new(0.8, 0.533333333333333, 0.6)
PRUSSIAN_BLUE =

Prussian blue: #003153

RGB.new(0.0, 0.192156862745098, 0.325490196078431)
PUMPKIN =

Pumpkin: #FF7518

RGB.new(1.0, 0.458823529411765, 0.0941176470588235)
PURPLE =

Purple: #660099

RGB.new(0.4, 0.0, 0.6)
RAW_UMBER =

Raw umber: #734A12

RGB.new(0.450980392156863, 0.290196078431373, 0.0705882352941176)
RED =

Red: #FF0000

RGB.new(1.0, 0.0, 0.0)
RED_VIOLET =

Red-violet: #C71585

RGB.new(0.780392156862745, 0.0823529411764706, 0.52156862745098)
ROBIN_EGG_BLUE =

Robin egg blue: #00CCCC

RGB.new(0.0, 0.8, 0.8)
ROSE =

Rose: #FF007F

RGB.new(1.0, 0.0, 0.498039215686275)
ROYAL_BLUE =

Royal Blue: #4169E1

RGB.new(0.254901960784314, 0.411764705882353, 0.882352941176471)
RUSSET =

Russet: #80461B

RGB.new(0.501960784313725, 0.274509803921569, 0.105882352941176)
RUST =

Rust: #B7410E

RGB.new(0.717647058823529, 0.254901960784314, 0.0549019607843137)
SAFETY_ORANGE =

Safety Orange (Blaze Orange): #FF6600

RGB.new(1.0, 0.4, 0.0)
BLAZE_ORANGE =
SAFETY_ORANGE
SAFFRON =

Saffron: #F4C430

RGB.new(0.956862745098039, 0.768627450980392, 0.188235294117647)
SAPPHIRE =

Sapphire: #082567

RGB.new(0.0313725490196078, 0.145098039215686, 0.403921568627451)
SALMON =

Salmon: #FF8C69

RGB.new(1.0, 0.549019607843137, 0.411764705882353)
SANDY_BROWN =

Sandy brown: #F4A460

RGB.new(0.956862745098039, 0.643137254901961, 0.376470588235294)
SANGRIA =

Sangria: #92000A

RGB.new(0.572549019607843, 0.0, 0.0392156862745098)
SCARLET =

Scarlet: #FF2400

RGB.new(1.0, 0.141176470588235, 0.0)
SCHOOL_BUS_YELLOW =

School bus yellow: #FFD800

RGB.new(1.0, 0.847058823529412, 0.0)
SEA_GREEN =

Sea Green: #2E8B57

RGB.new(0.180392156862745, 0.545098039215686, 0.341176470588235)
SEASHELL =

Seashell: #FFF5EE

RGB.new(1.0, 0.96078431372549, 0.933333333333333)
SELECTIVE_YELLOW =

Selective yellow: #FFBA00

RGB.new(1.0, 0.729411764705882, 0.0)
SEPIA =

Sepia: #704214

RGB.new(0.43921568627451, 0.258823529411765, 0.0784313725490196)
SHOCKING_PINK =

Shocking Pink: #FC0FC0

RGB.new(0.988235294117647, 0.0588235294117647, 0.752941176470588)
SILVER =

Silver: #C0C0C0

RGB.new(0.752941176470588, 0.752941176470588, 0.752941176470588)
SLATE_GRAY =

Slate gray: #708090

RGB.new(0.43921568627451, 0.501960784313725, 0.564705882352941)
SMALT =

Smalt (Dark powder blue): #003399

RGB.new(0.0, 0.2, 0.6)
DARK_POWDER_BLUE =
SMALT
SPRING_GREEN =

Spring Green: #00FF7F

RGB.new(0.0, 1.0, 0.498039215686275)
STEEL_BLUE =

Steel blue: #4682B4

RGB.new(0.274509803921569, 0.509803921568627, 0.705882352941177)
SWAMP_GREEN =

Swamp green: #ACB78E

RGB.new(0.674509803921569, 0.717647058823529, 0.556862745098039)
TAN =

Tan: #D2B48C

RGB.new(0.823529411764706, 0.705882352941177, 0.549019607843137)
TANGERINE =

Tangerine: #FFCC00

RGB.new(1.0, 0.8, 0.0)
TAUPE =

Taupe: #483C32

RGB.new(0.282352941176471, 0.235294117647059, 0.196078431372549)
TEA_GREEN =

Tea Green: #D0F0C0

RGB.new(0.815686274509804, 0.941176470588235, 0.752941176470588)
TEAL =

Teal: #008080

RGB.new(0.0, 0.501960784313725, 0.501960784313725)
TENNE =

Tenné (Tawny): #CD5700

RGB.new(0.803921568627451, 0.341176470588235, 0.0)
TAWNY =
TENNE
TERRA_COTTA =

Terra cotta: #E2725B

RGB.new(0.886274509803922, 0.447058823529412, 0.356862745098039)
THISTLE =

Thistle: #D8BFD8

RGB.new(0.847058823529412, 0.749019607843137, 0.847058823529412)
TURQUOISE =

Turquoise: #30D5C8

RGB.new(0.188235294117647, 0.835294117647059, 0.784313725490196)
ULTRAMARINE =

Ultramarine: #120A8F

RGB.new(0.0705882352941176, 0.0392156862745098, 0.56078431372549)
VERMILION =

Vermilion: #FF4D00

RGB.new(1.0, 0.301960784313725, 0.0)
VIOLET =

Violet: #8B00FF

RGB.new(0.545098039215686, 0.0, 1.0)
VIOLET_EGGPLANT =

Violet-eggplant: #991199

RGB.new(0.6, 0.0666666666666667, 0.6)
VIRIDIAN =

Viridian: #40826D

RGB.new(0.250980392156863, 0.509803921568627, 0.427450980392157)
WHEAT =

Wheat: #F5DEB3

RGB.new(0.96078431372549, 0.870588235294118, 0.701960784313725)
WHITE =

White: #FFFFFF

RGB.new(1.0, 1.0, 1.0)
WISTERIA =

Wisteria: #C9A0DC

RGB.new(0.788235294117647, 0.627450980392157, 0.862745098039216)
YELLOW =

Yellow: #FFFF00

RGB.new(1.0, 1.0, 0.0)
ZINNWALDITE =

Zinnwaldite: #EBC2AF

RGB.new(0.92156862745098, 0.76078431372549, 0.686274509803922)

Constants included from X11

X11::ANTIQUE_WHITE, X11::BISQUE, X11::BLANCHED_ALMOND, X11::BLUE_VIOLET, X11::BURLY_WOOD, X11::CADET_BLUE, X11::CORNSILK, X11::DARK_CYAN, X11::DARK_GOLDENROD, X11::DARK_GRAY, X11::DARK_GREEN, X11::DARK_KHAKI, X11::DARK_MAGENTA, X11::DARK_OLIVE_GREEN, X11::DARK_ORANGE, X11::DARK_ORCHID, X11::DARK_RED, X11::DARK_SALMON, X11::DARK_SEA_GREEN, X11::DARK_SLATE_BLUE, X11::DARK_SLATE_GRAY, X11::DARK_TURQUOISE, X11::DARK_VIOLET, X11::DEEP_PINK, X11::DEEP_SKY_BLUE, X11::DIM_GRAY, X11::FIRE_BRICK, X11::FLORAL_WHITE, X11::GAINSBORO, X11::GHOST_WHITE, X11::HONEYDEW, X11::INDIAN_RED, X11::LAWN_GREEN, X11::LIGHT_BLUE, X11::LIGHT_CORAL, X11::LIGHT_CYAN, X11::LIGHT_GOLDENROD_YELLOW, X11::LIGHT_GREEN, X11::LIGHT_GREY, X11::LIGHT_PINK, X11::LIGHT_SALMON, X11::LIGHT_SEA_GREEN, X11::LIGHT_SKY_BLUE, X11::LIGHT_SLATE_GRAY, X11::LIGHT_STEEL_BLUE, X11::LIGHT_YELLOW, X11::LIME_GREEN, X11::MEDIUM_AQUAMARINE, X11::MEDIUM_BLUE, X11::MEDIUM_ORCHID, X11::MEDIUM_SEA_GREEN, X11::MEDIUM_SLATE_BLUE, X11::MEDIUM_SPRING_GREEN, X11::MEDIUM_TURQUOISE, X11::MEDIUM_VIOLET_RED, X11::MINT_CREAM, X11::MISTY_ROSE, X11::MOCCASIN, X11::ORANGE_RED, X11::PALE_GOLDENROD, X11::PALE_GREEN, X11::PALE_TURQUOISE, X11::PALE_VIOLET_RED, X11::PEACH_PUFF, X11::PERU, X11::PLUM, X11::POWDER_BLUE, X11::ROSY_BROWN, X11::SADDLE_BROWN, X11::SIENNA, X11::SKY_BLUE, X11::SLATE_BLUE, X11::SNOW, X11::TOMATO, X11::WHITE_SMOKE, X11::YELLOW_GREEN

Class Method Summary collapse

Class Method Details

.parse(value, robust = false) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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