Class: Sketchup::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/sketchup-api-stubs/stubs/Sketchup/Color.rb

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.

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

Instance Method Summary collapse

Constructor Details

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

  • #initialize(red, green, blue, alpha = 255) ⇒ 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.

    • alpha (Integer) (defaults to: 255)

      A alpha value between 0 and 255.

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

  • #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.

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



222
223
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Color.rb', line 222

def initialize(*args)
end

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

Returns:

Version:

  • SketchUp 6.0



41
42
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Color.rb', line 41

def self.names
end

Instance Method Details

#==(other) ⇒ Boolean

The #== method checks to see if the two Sketchup::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)

Returns:

  • (Boolean)

Version:

  • SketchUp 2018



58
59
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Color.rb', line 58

def ==(other)
end

#alphaInteger

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:

  • (Integer)

Version:

  • SketchUp 6.0



71
72
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Color.rb', line 71

def alpha
end

#alpha=(alpha) ⇒ Integer, Float

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.

Returns:

  • (Integer, Float)

Version:

  • SketchUp 8.0 M1



87
88
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Color.rb', line 87

def alpha=(alpha)
end

#blend(color2, weight) ⇒ Sketchup::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 (Sketchup::Color)

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

  • weight (Float)

    A Float between 0.0 and 1.0

Returns:

Version:

  • SketchUp 6.0



111
112
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Color.rb', line 111

def blend(color2, weight)
end

#blueInteger

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

Returns:

  • (Integer)

Version:

  • SketchUp 6.0



125
126
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Color.rb', line 125

def blue
end

#blue=(blue) ⇒ Integer, Float

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.

Returns:

  • (Integer, Float)

Version:

  • SketchUp 6.0



142
143
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Color.rb', line 142

def blue=(blue)
end

#greenInteger

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

Returns:

  • (Integer)

Version:

  • SketchUp 6.0



156
157
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Color.rb', line 156

def green
end

#green=(green) ⇒ Integer, Float

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.

Returns:

  • (Integer, Float)

Version:

  • SketchUp 6.0



173
174
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Color.rb', line 173

def green=(green)
end

#redInteger

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

Returns:

  • (Integer)

Version:

  • SketchUp 6.0



236
237
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Color.rb', line 236

def red
end

#red=(red) ⇒ Integer, Float

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.

Returns:

  • (Integer, Float)

Version:

  • SketchUp 6.0



253
254
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Color.rb', line 253

def red=(red)
end

#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

Returns:

Version:

  • SketchUp 6.0



266
267
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Color.rb', line 266

def to_a
end

#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

Returns:

  • (Integer)

Version:

  • SketchUp 6.0



278
279
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Color.rb', line 278

def to_i
end

#to_sString

The #to_s method returns a string representation of the Sketchup::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

Returns:

Version:

  • SketchUp 6.0



291
292
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Color.rb', line 291

def to_s
end