Class: Sketchup::Color

Inherits:
Object
  • Object
show all

Overview

The Color class is used to create and manipulate colors within SketchUp models.

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 # collapse

  • .names ⇒ Object

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

Instance Method Summary # collapse

Constructor Details

#initialize(red, green, blue) ⇒ Sketchup::Color #initialize(name) ⇒ Sketchup::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)

# 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:

  • #initialize(red, green, blue) ⇒ Sketchup::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.

  • #initialize(name) ⇒ Sketchup::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.

Version:

  • SketchUp 6.0

Class Method Details

.namesObject

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

Returns:

  • names - an array of all SketchUp color names if successful

Version:

  • SketchUp 6.0

Instance Method Details

#alphaObject

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

Returns:

  • alpha - the opacity of the color if successful

Version:

  • SketchUp 6.0

#alpha=(alpha) ⇒ Object

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

Returns alpha - the newly set opacity value if successful

Parameters:

  • alpha

    The new opacity value.

Returns:

  • alpha - the newly set opacity value if successful

Version:

  • SketchUp 8.0 M1

#blend(color2, weight) ⇒ Object

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

Returns color3 - the newly blended Color object if successful

Parameters:

  • color2

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

  • weight

    A Float between 0.0 and 1.0

Returns:

  • color3 - the newly blended Color object if successful

Version:

  • SketchUp 6.0

#blueObject

The blue method is used to retrieve the blue value of a color. Colors are comprised of red, green, and blue values.

Value range is 0 to 255.

Examples:

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

Returns:

  • blue - the blue value for the color if successful

Version:

  • SketchUp 6.0

#blue=(blue) ⇒ Object

The blue= method is used to set the blue value of a color. Colors are comprised of red, green, and blue values.

Value range is 0 to 255.

Examples:

color = Sketchup::Color.new "AliceBlue"
setting = color.blue = 200
if (setting)
  UI.messagebox setting
else
  UI.messagebox "Failure"
end

Returns blue - the new blue value for the color if successful

Parameters:

  • blue

    The blue value for the color.

Returns:

  • blue - the new blue value for the color if successful

Version:

  • SketchUp 6.0

#greenObject

The green method is used to retrieve the green value of a color. Colors are comprised of red, green, and blue values.

Value range is 0 to 255.

Examples:

color = Sketchup::Color.new "AliceBlue"
setting = color.green
if (setting)
  UI.messagebox setting
else
  UI.messagebox "Failure"
end

Returns:

  • green - the green value for the color if successful

Version:

  • SketchUp 6.0

#green=(green) ⇒ Object

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"
setting = color.green = 200
if (setting)
  UI.messagebox setting
else
  UI.messagebox "Failure"
end

Returns green - the new green value for the color if successful

Parameters:

  • green

    The green value for the color.

Returns:

  • green - the new green value for the color if successful

Version:

  • SketchUp 6.0

#redObject

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"
setting = color.red
if (setting)
  UI.messagebox setting
else
  UI.messagebox "Failure"
end

Returns:

  • red - the red value for the color if successful

Version:

  • SketchUp 6.0

#red=(red) ⇒ Object

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"
setting = color.red=200

Returns red - the new red value for the color if successful

Parameters:

  • red

    The red value for the color.

Returns:

  • red - the new red value for the color if successful

Version:

  • SketchUp 6.0

#to_aObject

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
if (color_array)
  UI.messagebox color_array.to_s
else
  UI.messagebox "Failure"
end

Returns:

  • array - an Array object if successful

Version:

  • SketchUp 6.0

#to_iObject

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

Returns:

  • integer - a 32 bit integer if successful

Version:

  • SketchUp 6.0

#to_sObject

Returns a string representation of a Color object, in the form of “Color(255, 255, 255, 255)”.

Examples:

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

Returns:

  • string - a String name for the Color.

Version:

  • SketchUp 6.0