Color
A color represented in RGBA format.
Color.swift:21struct Color
A color represented in RGBA format by a red (r
), green (g
), blue (b
), and alpha (a
) component. Each component is a 32-bit floating-point value, usually ranging from 0.0
to 1.0
. Some properties (such as modulate
) may support values greater than 1.0
, for overbright or HDR (High Dynamic Range) colors.
Colors can be created in various ways: By the various Color
constructors, by static methods such as fromHsv(h:s:v:alpha:)
, and by using a name from the set of standardized colors based on X11 color names with the addition of TRANSPARENT
. GDScript also provides @GDScript.Color8
, which uses integers from 0
to 255
and doesn’t support overbright colors.
Citizens in SwiftGodot
Conformances
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol DoubleScalable
protocol Equatable
A type that can be compared for value equality.
protocol Escapable
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol IntScalable
protocol LinearInterpolation
protocol SelfVariantRepresentable
Structs and scalar types use their own layout for storage.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Type members
init(
) Constructs a default
Color
from opaque black. This is the same asBLACK
.init(code: String
) Constructs a
Color
either from an HTML color code or from a standardized color name. The supported color names are the same as the constants.init(code: String, alpha: Float
) Constructs a
Color
either from an HTML color code or from a standardized color name, withalpha
on the range of 0.0 to 1.0. The supported color names are the same as the constants.init(from: Color
) init(from: Color, alpha: Float
) Constructs a
Color
from the existing color, witha
set to the givenalpha
value.init(r: Float, g: Float, b: Float
) Constructs a
Color
from RGB values, typically between 0.0 and 1.0.a
is set to 1.0.init(r: Float, g: Float, b: Float, a: Float
) Constructs a
Color
from RGBA values, typically between 0.0 and 1.0.static let aliceBlue: Color
Alice blue color.
static let antiqueWhite: Color
Antique white color.
static let aqua: Color
Aqua color.
static let aquamarine: Color
Aquamarine color.
static let azure: Color
Azure color.
static let beige: Color
Beige color.
static let bisque: Color
Bisque color.
static let black: Color
Black color. In GDScript, this is the default value of any color.
static let blanchedAlmond: Color
Blanched almond color.
static let blue: Color
Blue color.
static let blueViolet: Color
Blue violet color.
static let brown: Color
Brown color.
static let burlywood: Color
Burlywood color.
static let cadetBlue: Color
Cadet blue color.
static let chartreuse: Color
Chartreuse color.
static let chocolate: Color
Chocolate color.
static let coral: Color
Coral color.
static let cornflowerBlue: Color
Cornflower blue color.
static let cornsilk: Color
Cornsilk color.
static let crimson: Color
Crimson color.
static let cyan: Color
Cyan color.
static let darkBlue: Color
Dark blue color.
static let darkCyan: Color
Dark cyan color.
static let darkGoldenrod: Color
Dark goldenrod color.
static let darkGray: Color
Dark gray color.
static let darkGreen: Color
Dark green color.
static let darkKhaki: Color
Dark khaki color.
static let darkMagenta: Color
Dark magenta color.
static let darkOliveGreen: Color
Dark olive green color.
static let darkOrange: Color
Dark orange color.
static let darkOrchid: Color
Dark orchid color.
static let darkRed: Color
Dark red color.
static let darkSalmon: Color
Dark salmon color.
static let darkSeaGreen: Color
Dark sea green color.
static let darkSlateBlue: Color
Dark slate blue color.
static let darkSlateGray: Color
Dark slate gray color.
static let darkTurquoise: Color
Dark turquoise color.
static let darkViolet: Color
Dark violet color.
static let deepPink: Color
Deep pink color.
static let deepSkyBlue: Color
Deep sky blue color.
static let dimGray: Color
Dim gray color.
static let dodgerBlue: Color
Dodger blue color.
static let firebrick: Color
Firebrick color.
static let floralWhite: Color
Floral white color.
static let forestGreen: Color
Forest green color.
static let fuchsia: Color
Fuchsia color.
static let gainsboro: Color
Gainsboro color.
static let ghostWhite: Color
Ghost white color.
static var godotType: Variant.GType
static let gold: Color
Gold color.
static let goldenrod: Color
Goldenrod color.
static let gray: Color
Gray color.
static let green: Color
Green color.
static let greenYellow: Color
Green yellow color.
static let honeydew: Color
Honeydew color.
static let hotPink: Color
Hot pink color.
static let indianRed: Color
Indian red color.
static let indigo: Color
Indigo color.
static let ivory: Color
Ivory color.
static let khaki: Color
Khaki color.
static let lavender: Color
Lavender color.
static let lavenderBlush: Color
Lavender blush color.
static let lawnGreen: Color
Lawn green color.
static let lemonChiffon: Color
Lemon chiffon color.
static let lightBlue: Color
Light blue color.
static let lightCoral: Color
Light coral color.
static let lightCyan: Color
Light cyan color.
static let lightGoldenrod: Color
Light goldenrod color.
static let lightGray: Color
Light gray color.
static let lightGreen: Color
Light green color.
static let lightPink: Color
Light pink color.
static let lightSalmon: Color
Light salmon color.
static let lightSeaGreen: Color
Light sea green color.
static let lightSkyBlue: Color
Light sky blue color.
static let lightSlateGray: Color
Light slate gray color.
static let lightSteelBlue: Color
Light steel blue color.
static let lightYellow: Color
Light yellow color.
static let lime: Color
Lime color.
static let limeGreen: Color
Lime green color.
static let linen: Color
Linen color.
static let magenta: Color
Magenta color.
static let maroon: Color
Maroon color.
static let mediumAquamarine: Color
Medium aquamarine color.
static let mediumBlue: Color
Medium blue color.
static let mediumOrchid: Color
Medium orchid color.
static let mediumPurple: Color
Medium purple color.
static let mediumSeaGreen: Color
Medium sea green color.
static let mediumSlateBlue: Color
Medium slate blue color.
static let mediumSpringGreen: Color
Medium spring green color.
static let mediumTurquoise: Color
Medium turquoise color.
static let mediumVioletRed: Color
Medium violet red color.
static let midnightBlue: Color
Midnight blue color.
static let mintCream: Color
Mint cream color.
static let mistyRose: Color
Misty rose color.
static let moccasin: Color
Moccasin color.
static let oldLace: Color
Old lace color.
static let olive: Color
Olive color.
static let oliveDrab: Color
Olive drab color.
static let orange: Color
Orange color.
static let orangeRed: Color
Orange red color.
static let orchid: Color
Orchid color.
static let paleGoldenrod: Color
Pale goldenrod color.
static let paleGreen: Color
Pale green color.
static let paleTurquoise: Color
Pale turquoise color.
static let paleVioletRed: Color
Pale violet red color.
static let papayaWhip: Color
Papaya whip color.
static let peachPuff: Color
Peach puff color.
static let peru: Color
Peru color.
static let pink: Color
Pink color.
static let plum: Color
Plum color.
static let powderBlue: Color
Powder blue color.
static let purple: Color
Purple color.
static let rebeccaPurple: Color
Rebecca purple color.
static let red: Color
Red color.
static let rosyBrown: Color
Rosy brown color.
static let royalBlue: Color
Royal blue color.
static let saddleBrown: Color
Saddle brown color.
static let salmon: Color
Salmon color.
static let sandyBrown: Color
Sandy brown color.
static let seaGreen: Color
Sea green color.
static let seashell: Color
Seashell color.
static let sienna: Color
Sienna color.
static let silver: Color
Silver color.
static let skyBlue: Color
Sky blue color.
static let slateBlue: Color
Slate blue color.
static let slateGray: Color
Slate gray color.
static let snow: Color
Snow color.
static let springGreen: Color
Spring green color.
static let steelBlue: Color
Steel blue color.
static let tan: Color
Tan color.
static let teal: Color
Teal color.
static let thistle: Color
Thistle color.
static let tomato: Color
Tomato color.
static let transparent: Color
Transparent color (white with zero alpha).
static let turquoise: Color
Turquoise color.
static let violet: Color
Violet color.
static let webGray: Color
Web gray color.
static let webGreen: Color
Web green color.
static let webMaroon: Color
Web maroon color.
static let webPurple: Color
Web purple color.
static let wheat: Color
Wheat color.
static let white: Color
White color.
static let whiteSmoke: Color
White smoke color.
static let yellow: Color
Yellow color.
static let yellowGreen: Color
Yellow green color.
static func fromHsv(h: Double, s: Double, v: Double, alpha: Double
) -> Color Constructs a color from an HSV profile. The hue (
h
), saturation (s
), and value (v
) are typically between 0.0 and 1.0.static func fromOkHsl(h: Double, s: Double, l: Double, alpha: Double
) -> Color Constructs a color from an OK HSL profile. The hue (
h
), saturation (s
), and lightness (l
) are typically between 0.0 and 1.0.static func fromRgbe9995(rgbe: Int64
) -> Color Decodes a
Color
from an RGBE9995 format integer. Seergbe9995
.static func fromString(str: String, default: Color
) -> Color Creates a
Color
from the given string, which can be either an HTML color code or a named color (case-insensitive). Returnsdefault
if the color cannot be inferred from the string.static func hex(hex: Int64
) -> Color Returns the
Color
associated with the providedhex
integer in 32-bit RGBA format (8 bits per channel). This method is the inverse oftoRgba32
.static func hex64(hex: Int64
) -> Color Returns the
Color
associated with the providedhex
integer in 64-bit RGBA format (16 bits per channel). This method is the inverse oftoRgba64
.static func html(rgba: String
) -> Color Returns a new color from
rgba
, an HTML hexadecimal color string.rgba
is not case-sensitive, and may be prefixed by a hash sign (#
).static func htmlIsValid(color: String
) -> Bool Returns
true
ifcolor
is a valid HTML hexadecimal color string. The string must be a hexadecimal value (case-insensitive) of either 3, 4, 6 or 8 digits, and may be prefixed by a hash sign (#
). This method is identical toString/isValidHtmlColor()
.static func != (lhs: Color, rhs: Color
) -> Bool Returns
true
if the colors are not exactly equal.static func * (lhs: Color, rhs: Color
) -> Color Multiplies each component of the
Color
by the components of the givenColor
.static func * (lhs: Color, rhs: Double
) -> Color Multiplies each component of the
Color
by the given float.static func * (lhs: Color, rhs: Int64
) -> Color Multiplies each component of the
Color
by the given integer.static func + (lhs: Color, rhs: Color
) -> Color Adds each component of the
Color
with the components of the givenColor
.static func - (c: `Self`
) -> Color Inverts the given color. This is equivalent to Color.WHITE - c or Color(1 - c.r, 1 - c.g, 1 - c.b, 1 - c.a). Unlike with inverted, the a component is inverted, too.
static func - (lhs: Color, rhs: Color
) -> Color Subtracts each component of the
Color
by the components of the givenColor
.static func / (lhs: Color, rhs: Color
) -> Color Divides each component of the
Color
by the components of the givenColor
.static func / (lhs: Color, rhs: Double
) -> Color Divides each component of the
Color
by the given float.static func / (lhs: Color, rhs: Int64
) -> Color Divides each component of the
Color
by the given integer.static func == (lhs: Color, rhs: Color
) -> Bool Returns
true
if the colors are exactly equal.
Instance members
var alpha: Float
The color’s alpha component, typically on the range of 0 to 1. A value of 0 means that the color is fully transparent. A value of 1 means that the color is fully opaque.
var blue: Float
The color’s blue component, typically on the range of 0 to 1.
var green: Float
The color’s green component, typically on the range of 0 to 1.
var hue: Float
The HSV hue of this color, on the range 0 to 1.
var red: Float
The color’s red component, typically on the range of 0 to 1.
var saturation: Float
The HSV saturation of this color, on the range 0 to 1.
var value: Float
The HSV value (brightness) of this color, on the range 0 to 1.
subscript(Int64
) -> Double func blend(over: Color
) -> Color Returns a new color resulting from overlaying this color over the given color. In a painting program, you can imagine it as the
over
color painted over this color (including alpha).func clamp(min: Color, max: Color
) -> Color Returns a new color with all components clamped between the components of
min
andmax
, by running@GlobalScope.clamp
on each component.func darkened(amount: Double
) -> Color Returns a new color resulting from making this color darker by the specified
amount
(ratio from 0.0 to 1.0). See alsolightened(amount:)
.func getLuminance(
) -> Double Returns the light intensity of the color, as a value between 0.0 and 1.0 (inclusive). This is useful when determining light or dark color. Colors with a luminance smaller than 0.5 can be generally considered dark.
func inverted(
) -> Color Returns the color with its
r
,g
, andb
components inverted ((1 - r, 1 - g, 1 - b, a)
).func isEqualApprox(to: Color
) -> Bool Returns
true
if this color andto
are approximately equal, by running@GlobalScope.is_equal_approx
on each component.func lerp(to: `Self`, weight: any BinaryFloatingPoint
) -> Color func lightened(amount: Double
) -> Color Returns a new color resulting from making this color lighter by the specified
amount
, which should be a ratio from 0.0 to 1.0. See alsodarkened(amount:)
.func linearToSrgb(
) -> Color Returns the color converted to the sRGB color space. This method assumes the original color is in the linear color space. See also
srgbToLinear
which performs the opposite operation.func srgbToLinear(
) -> Color Returns the color converted to the linear color space. This method assumes the original color already is in the sRGB color space. See also
linearToSrgb
which performs the opposite operation.func toAbgr32(
) -> Int64 Returns the color converted to a 32-bit integer in ABGR format (each component is 8 bits). ABGR is the reversed version of the default RGBA format.
func toAbgr64(
) -> Int64 Returns the color converted to a 64-bit integer in ABGR format (each component is 16 bits). ABGR is the reversed version of the default RGBA format.
func toArgb32(
) -> Int64 Returns the color converted to a 32-bit integer in ARGB format (each component is 8 bits). ARGB is more compatible with DirectX.
func toArgb64(
) -> Int64 Returns the color converted to a 64-bit integer in ARGB format (each component is 16 bits). ARGB is more compatible with DirectX.
func toHtml(withAlpha: Bool
) -> String Returns the color converted to an HTML hexadecimal color
String
in RGBA format, without the hash (#
) prefix.func toRgba32(
) -> Int64 Returns the color converted to a 32-bit integer in RGBA format (each component is 8 bits). RGBA is Godot’s default format. This method is the inverse of
hex(hex:)
.func toRgba64(
) -> Int64 Returns the color converted to a 64-bit integer in RGBA format (each component is 16 bits). RGBA is Godot’s default format. This method is the inverse of
hex64(hex:)
.
Type features
init?(Variant
) static func makeOrUnwrap(Variant
) -> Self? Unwraps an object from a variant.
static func makeOrUnwrap(Variant
) -> Self? Unwraps an object from a variant. This is useful when you want one method to call that will return the unwrapped Variant, regardless of whether it is a SwiftGodot.Object or not.
static func != (lhs: Self, rhs: Self
) -> Bool Returns a Boolean value indicating whether two values are not equal.
static func * (lhs: Self, rhs: Int
) -> Self static func *= (lhs: inout Self, rhs: Int
) static func *= (lhs: inout Self, rhs: Double
) static func / (lhs: Self, rhs: Int
) -> Self static func /= (lhs: inout Self, rhs: Int
) static func /= (lhs: inout Self, rhs: Double
)