123456789_123456789_123456789_123456789_123456789_

Class: Sketchup::Color

Relationships
Inherits: Object

Overview

The Color class is used to create and manipulate colors within SketchUp Models. The class can also be used the same way with LayOut documents.

For methods that accept a Color object, such as the face.material method, you can pass in an actual Color object, or an object that can be converted to a Color. For example:

SketchUp ships with several built in colors in the Materials Browser. These colors are listed in the following table.

NameRGB ValuesSwatch
AliceBlue240,248,255  
AntiqueWhite250,235,215  
Aqua0,255,255  
Aquamarine127,255,212  
Azure240,255,255  
Beige245,245,220  
Bisque255,228,196  
Black0,0,0  
BlanchedAlmond255,235,205  
Blue0,0,255  
BlueViolet138,43,226  
Brown165,42,42  
BurlyWood222,184,135  
CadetBlue95,158,160  
Chartreuse127,255,0  
Chocolate210,105,30  
Coral255,127,80  
CornflowerBlue100,149,237  
Cornsilk255,248,220  
Crimson220,20,60  
Cyan0,255,255  
DarkBlue0,0,139  
DarkCyan0,139,139  
DarkGoldenrod184,134,11  
DarkGray169,169,169  
DarkGreen0,100,0  
DarkKhaki189,183,107  
DarkMagenta139,0,139  
DarkOliveGreen85,107,47  
DarkOrange255,140,0  
DarkOrchid153,50,204  
DarkRed139,0,0  
DarkSalmon233,150,122  
DarkSeaGreen143,188,143  
DarkSlateBlue72,61,139  
DarkSlateGray47,79,79  
DarkTurquoise0,206,209  
DarkViolet148,0,211  
DeepPink255,20,147  
DeepSkyBlue0,191,255  
DimGray105,105,105  
DodgerBlue30,144,255  
FireBrick178,34,34  
FloralWhite255,250,240  
ForestGreen34,139,34  
Fuchsia255,0,255  
Gainsboro220,220,220  
GhostWhite248,248,255  
Gold255,215,0  
Goldenrod218,165,32  
Gray128,128,128  
Green0,128,0  
GreenYellow173,255,47  
Honeydew240,255,240  
HotPink255,105,180  
IndianRed205,92,92  
Indigo75,0,130  
Ivory255,255,240  
Khaki240,230,140  
Lavender230,230,250  
LavenderBlush255,240,245  
LawnGreen124,252,0  
LemonChiffon255,250,205  
LightBlue173,216,230  
LightCoral240,128,128  
LightCyan224,255,255  
LightGoldenrodYellow250,250,210  
LightGreen144,238,144  
LightGrey211,211,211  
LightPink255,182,193  
LightSalmon255,160,122  
LightSeaGreen32,178,170  
LightSkyBlue135,206,250  
LightSlateGray119,136,153  
LightSteelBlue176,196,222  
LightYellow255,255,224  
Lime0,255,0  
LimeGreen50,205,50  
Linen250,240,230  
Magenta255,0,255  
Maroon128,0,0  
MediumAquamarine102,205,170  
MediumBlue0,0,205  
MediumOrchid186,85,211  
MediumPurple147,112,219  
MediumSeaGreen60,179,113  
MediumSlateBlue123,104,238  
MediumSpringGreen0,250,154  
MediumTurquoise72,209,204  
MediumVioletRed199,21,133  
MidnightBlue25,25,112  
MintCream245,255,250  
MistyRose255,228,225  
Moccasin255,228,181  
NavajoWhite255,222,173  
Navy0,0,128  
OldLace253,245,230  
Olive128,128,0  
OliveDrab107,142,35  
Orange255,165,0  
OrangeRed255,69,0  
Orchid218,112,214  
PaleGoldenrod238,232,170  
PaleGreen152,251,152  
PaleTurquoise175,238,238  
PaleVioletRed219,112,147  
PapayaWhip255,239,213  
PeachPuff255,218,185  
Peru205,133,63  
Pink255,192,203  
Plum221,160,221  
PowderBlue176,224,230  
Purple128,0,128  
Red255,0,0  
RosyBrown188,143,143  
RoyalBlue65,105,225  
SaddleBrown139,69,19  
Salmon250,128,114  
SandyBrown244,164,96  
SeaGreen46,139,87  
Seashell255,245,238  
Sienna160,82,45  
Silver192,192,192  
SkyBlue135,206,235  
SlateBlue106,90,205  
SlateGray112,128,144  
Snow255,250,250  
SpringGreen0,255,127  
SteelBlue70,130,180  
Tan210,180,140  
Teal0,128,128  
Thistle216,191,216  
Tomato255,99,71  
Turquoise64,224,208  
Violet238,130,238  
Wheat245,222,179  
White255,255,255  
WhiteSmoke245,245,245  
Yellow255,255,0  
YellowGreen154,205,50  

Examples:

face.material = Sketchup::Color.new(255, 0, 0)
face.material = 255
face.material = 0xff
face.material = "red"
face.material = "#ff0000"
face.material = [1.0, 0.0, 0.0]
face.material = [255, 0, 0]

Version:

  • SketchUp 6.0

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(red, green, blue, alpha = 255) ⇒ Color .new(red, green, blue, alpha = 1.0) ⇒ Color .new(name) ⇒ Color .new(hex) ⇒ Color

The new method is used to create a new Color object.

Examples:

color_from_name = Sketchup::Color.new "OldLace"
color_from_rgb = Sketchup::Color.new(0, 128, 255)
color_from_rgba = Sketchup::Color.new(0, 128, 255, 128)
color_from_hex = Sketchup::Color.new(0xFF0000)

# You can then assign colors to the material of DrawingElements.
# Note that this creates a new Material object, and the alpha value
# of the color does NOT get applied to the new Material. You must
# manually set the alpha to get transparent materials.
face.material = color_from_rgba
face.material.alpha = 0.5

Overloads:

  • .new(red, green, blue, alpha = 255) ⇒ Color

    Parameters:

    • red (Integer)

      A red value between 0 and 255.

    • green (Integer)

      A green value between 0 and 255.

    • blue (Integer)

      A blue value between 0 and 255.

    • alpha (Integer) (defaults to: 255)

      A alpha value between 0 and 255.

  • .new(red, green, blue, alpha = 1.0) ⇒ Color

    Parameters:

    • red (Float)

      A red value between 0.0 and 1.0.

    • green (Float)

      A green value between 0.0 and 1.0.

    • blue (Float)

      A blue value between 0.0 and 1.0.

    • alpha (Float) (defaults to: 1.0)

      A alpha value between 0.0 and 1.0.

  • .new(name) ⇒ Color

    Parameters:

    • name (String)

      A string name of a color that currently exists in SketchUp. See the table at the start of this class description for more info.

  • .new(hex) ⇒ Color
    Note:

    When assigning colors via a hexadecimal, R and B will be flipped.

    Note:

    When assigning colors via a hexadecimal, Alpha is not supported.

    Parameters:

    • hex (Integer)

      A hexadecimal color code.

Version:

  • SketchUp 6.0

Class Method Details

.namesArray

The .names method is used to retrieve an array of all color names recognized by SketchUp.

In general, whenever a method wants a color, you can pass in a ::String with one of these names.

Examples:

array = Sketchup::Color.names

Version:

  • SketchUp 6.0

Instance Attribute Details

#alphaInteger (rw)

The #alpha method is used to retrieve the opacity of the color. A value of 0 is transparent, 255 is opaque.

Examples:

color = Sketchup::Color.new "OldLace"
alpha = color.alpha

Version:

  • SketchUp 6.0

#alpha=(alpha) ⇒ Integer, Float (rw)

The #alpha= method is used to set the opacity of the color. A value of 0 is transparent, 255 is opaque.

Examples:

color = Sketchup::Color.new "AliceBlue"
alpha = color.alpha = 255

Parameters:

  • alpha (Integer, Float)

    The new opacity value.

Version:

  • SketchUp 8.0 M1

#blueInteger (rw)

The #blue method is used to retrieve the blue value of a color.

Value range is 0 to 255.

Examples:

color = Sketchup::Color.new "AliceBlue"
blue = color.blue

Version:

  • SketchUp 6.0

#blue=(blue) ⇒ Integer, Float (rw)

The #blue= method is used to set the blue value of a color.

Value range is 0 to 255.

Examples:

color = Sketchup::Color.new "AliceBlue"
blue = color.blue = 200

Parameters:

  • blue (Integer, Float)

    The blue value for the color.

Version:

  • SketchUp 6.0

#greenInteger (rw)

The #green method is used to retrieve the green value of a color.

Value range is 0 to 255.

Examples:

color = Sketchup::Color.new "AliceBlue"
green = color.green

Version:

  • SketchUp 6.0

#green=(green) ⇒ Integer, Float (rw)

The #green= method is used to set the green component of a RGB Color.

Value range is 0 to 255.

Examples:

color = Sketchup::Color.new "AliceBlue"
green = color.green = 200

Parameters:

  • green (Integer, Float)

    The green value for the color.

Version:

  • SketchUp 6.0

#redInteger (rw)

The #red method is used to retrieve the red component of a RGB Color.

Value range is 0 to 255.

Examples:

color = Sketchup::Color.new "AliceBlue"
red = color.red

Version:

  • SketchUp 6.0

#red=(red) ⇒ Integer, Float (rw)

The #red= method is used to set the red component of a RGB Color.

Value range is 0 to 255.

Examples:

color = Sketchup::Color.new "AliceBlue"
red = color.red=200

Parameters:

  • red (Integer, Float)

    The red value for the color.

Version:

  • SketchUp 6.0

Instance Method Details

#==(other) ⇒ Boolean

The #== method checks to see if the two Colors are equal. This checks whether the RGBA values are the same. In versions prior to SketchUp 2018 two color objects with the same values would be considered different.

Examples:

SketchUp::Color.new(255, 255, 255) == Sketchup::Color.new(1.0, 1.0, 1.0)

Parameters:

  • other (Object)

Version:

  • SketchUp 2018

#blend(color2, weight) ⇒ Color

The #blend method is used to blend two colors.

The blended color will be the result of taking (1 - weight) * color1 + weight * color2. If weight = 0, you will get color2. If weight = 1 you will get color1.

Examples:

color1 = Sketchup::Color.new "OldLace"
color2 = Sketchup::Color.new "AliceBlue"
color3 = color1.blend color2, 0.5

Parameters:

  • color2 (Color)

    The second color to be blended (with this color).

  • weight (Float)

    A Float between 0.0 and 1.0

Version:

  • SketchUp 6.0

#to_aArray

The #to_a method is used to convert a Color object to an ::Array object. The returned array will contain 4 integer values (RGBA) between 0 and 255.

Examples:

color = Sketchup::Color.new "AliceBlue"
color_array = color.to_a

Version:

  • SketchUp 6.0

#to_iInteger

The #to_i method is used to convert a Color object to an 32 bit integer.

Examples:

color = Sketchup::Color.new "AliceBlue"
integer = color.to_i

Version:

  • SketchUp 6.0

#to_sString

The #to_s method returns a string representation of the Color object, in the form of “Color(255, 255, 255, 255)”.

Examples:

color = Sketchup::Color.new(255, 255, 255, 255)
color_str = color.to_s

Version:

  • SketchUp 6.0