Class: ModraUp::Color
- Inherits:
-
Object
- Object
- ModraUp::Color
Overview
RGBA colors. The integers in the constructor are handled as bytes, floats are multiplied by 255, truncated, and clamped to the range 0–255.
Class Method Summary # collapse
-
.new ⇒ ModraUp::Color
Construct a color. With no parameters, it initializes to black and opaque. The name can be a name from ModraUp::Color.names (case-insensitive), or a CSS hexadecimal value (#rgb / #rrggbb). Each channel can accept an integer or a float (e.g., 0.5 → 127), with values clamped to the range 0–255. A single integer is parsed as 0xBBGGRR, with higher bits ignored, and alpha is set to 255.
-
.names ⇒ Array<String>
Known color names (from the SketchUp Materials Browser / CSS table). ModraUp::View#drawing_color= also recognizes these names.
Instance Method Summary # collapse
-
#red ⇒ Integer
Red channel (0–255).
-
#green ⇒ Integer
Green channel (0–255).
-
#blue ⇒ Integer
Blue channel (0–255).
-
#alpha ⇒ Integer
Opacity channel (0–255).
-
#red= ⇒ Numeric
Set the red channel. Decimal values are truncated to bytes, with results ranging from 0–255.
-
#green= ⇒ Numeric
Set the green channel. Decimal values are truncated to the nearest byte, and the result must be in the range 0–255.
-
#blue= ⇒ Numeric
Set the blue channel. Decimal values are truncated to bytes, with results ranging from 0–255.
-
#alpha= ⇒ Numeric
Set opacity. Integer must be in the range 0–255, Float must be in the range 0.0–1.0, scaled to bytes (0.5 → 127).
-
#to_a ⇒ Array<Integer>
Returns [red, green, blue, alpha].
-
#to_i ⇒ Integer
Returns an integer in the format 0xBBGGRR, excluding alpha.
-
#to_s ⇒ String
Returns a four-channel description, such as Color( 18, 52, 86, 255).
-
#blend(other, weight) ⇒ ModraUp::Color
Returns a new color, blending the RGBA channels with the formula: +new_color = +self + weight * (other - self) +, where fractional parts are truncated and the result is clamped to the range 0–255. The input colors are not modified; the other color can be any value accepted by the constructor.
-
#== ⇒ Boolean
If all four channels are equal, it returns true.
Class Method Details
Color.new ⇒ colorColor.new(red, green, blue) ⇒ colorColor.new(red, green, blue, alpha) ⇒ colorColor.new([red, green, blue]) ⇒ colorColor.new(name) ⇒ colorColor.new(color) ⇒ colorColor.new(integer) ⇒ color
Construct a color. With no parameters, it initializes to black and opaque. The name can be a name from ModraUp::Color.names (case-insensitive), or a CSS hexadecimal value (#rgb / #rrggbb). Each channel can accept an integer or a float (e.g., 0.5 → 127), with values clamped to the range 0–255. A single integer is parsed as 0xBBGGRR, with higher bits ignored, and alpha is set to 255.
Color.names ⇒ Array<String>
Known color names (from the SketchUp Materials Browser / CSS table). ModraUp::View#drawing_color= also recognizes these names.
Instance Method Details
color.red ⇒ Integer
Red channel (0–255).
color.green ⇒ Integer
Green channel (0–255).
color.blue ⇒ Integer
Blue channel (0–255).
color.alpha ⇒ Integer
Opacity channel (0–255).
color.red = value ⇒ value
Set the red channel. Decimal values are truncated to bytes, with results ranging from 0–255.
color.green = value ⇒ value
Set the green channel. Decimal values are truncated to the nearest byte, and the result must be in the range 0–255.
color.blue = value ⇒ value
Set the blue channel. Decimal values are truncated to bytes, with results ranging from 0–255.
color.alpha = value ⇒ value
Set opacity. Integer must be in the range 0–255, Float must be in the range 0.0–1.0, scaled to bytes (0.5 → 127).
color.to_a ⇒ Array<Integer>
Returns [red, green, blue, alpha].
color.to_i ⇒ Integer
Returns an integer in the format 0xBBGGRR, excluding alpha.
color.to_s ⇒ String
Returns a four-channel description, such as Color( 18, 52, 86, 255).
color.blend(other, weight) ⇒ ModraUp::Color
Returns a new color, blending the RGBA channels with the formula: +new_color = +self + weight * (other - self) +, where fractional parts are truncated and the result is clamped to the range 0–255. The input colors are not modified; the other color can be any value accepted by the constructor.
color == other ⇒ Boolean
If all four channels are equal, it returns true.