Files
godot-docs/classes/class_color.rst
2018-04-10 10:44:10 +02:00

282 lines
12 KiB
ReStructuredText

.. Generated automatically by doc/tools/makerst.py in Godot's source tree.
.. DO NOT EDIT THIS FILE, but the Color.xml source instead.
.. The source is found in doc/classes or modules/<name>/doc_classes.
.. _class_Color:
Color
=====
**Category:** Built-In Types
Brief Description
-----------------
Color in RGBA format with some support for ARGB format.
Member Functions
----------------
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Color<class_color>` | :ref:`Color<class_Color_Color>` **(** :ref:`float<class_float>` r, :ref:`float<class_float>` g, :ref:`float<class_float>` b, :ref:`float<class_float>` a **)** |
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Color<class_color>` | :ref:`Color<class_Color_Color>` **(** :ref:`float<class_float>` r, :ref:`float<class_float>` g, :ref:`float<class_float>` b **)** |
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Color<class_color>` | :ref:`Color<class_Color_Color>` **(** :ref:`int<class_int>` from **)** |
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Color<class_color>` | :ref:`Color<class_Color_Color>` **(** :ref:`String<class_string>` from **)** |
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Color<class_color>` | :ref:`blend<class_Color_blend>` **(** :ref:`Color<class_color>` over **)** |
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Color<class_color>` | :ref:`contrasted<class_Color_contrasted>` **(** **)** |
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Color<class_color>` | :ref:`darkened<class_Color_darkened>` **(** :ref:`float<class_float>` amount **)** |
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`gray<class_Color_gray>` **(** **)** |
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Color<class_color>` | :ref:`inverted<class_Color_inverted>` **(** **)** |
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Color<class_color>` | :ref:`lightened<class_Color_lightened>` **(** :ref:`float<class_float>` amount **)** |
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Color<class_color>` | :ref:`linear_interpolate<class_Color_linear_interpolate>` **(** :ref:`Color<class_color>` b, :ref:`float<class_float>` t **)** |
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`to_argb32<class_Color_to_argb32>` **(** **)** |
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`String<class_string>` | :ref:`to_html<class_Color_to_html>` **(** :ref:`bool<class_bool>` with_alpha=True **)** |
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`to_rgba32<class_Color_to_rgba32>` **(** **)** |
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
Member Variables
----------------
.. _class_Color_a:
- :ref:`float<class_float>` **a** - Alpha (0 to 1)
.. _class_Color_a8:
- :ref:`int<class_int>` **a8** - Alpha (0 to 255)
.. _class_Color_b:
- :ref:`float<class_float>` **b** - Blue (0 to 1)
.. _class_Color_b8:
- :ref:`int<class_int>` **b8** - Blue (0 to 255)
.. _class_Color_g:
- :ref:`float<class_float>` **g** - Green (0 to 1)
.. _class_Color_g8:
- :ref:`int<class_int>` **g8** - Green (0 to 255)
.. _class_Color_h:
- :ref:`float<class_float>` **h** - Hue (0 to 1)
.. _class_Color_r:
- :ref:`float<class_float>` **r** - Red (0 to 1)
.. _class_Color_r8:
- :ref:`int<class_int>` **r8** - Red (0 to 255)
.. _class_Color_s:
- :ref:`float<class_float>` **s** - Saturation (0 to 1)
.. _class_Color_v:
- :ref:`float<class_float>` **v** - Value (0 to 1)
Description
-----------
A color is represented as red, green and blue (r,g,b) components. Additionally, "a" represents the alpha component, often used for transparency. Values are in floating point and usually range from 0 to 1. Some methods (such as set_modulate(color)) may accept values > 1.
You can also create a color from standardised color names with :ref:`@GDScript.ColorN<class_@GDScript_ColorN>`.
Member Function Description
---------------------------
.. _class_Color_Color:
- :ref:`Color<class_color>` **Color** **(** :ref:`float<class_float>` r, :ref:`float<class_float>` g, :ref:`float<class_float>` b, :ref:`float<class_float>` a **)**
Constructs a color from an RGBA profile using values between 0 and 1 (float).
::
var c = Color(0.2, 1.0, .7, .8) # a color of an RGBA(51, 255, 178, 204)
.. _class_Color_Color:
- :ref:`Color<class_color>` **Color** **(** :ref:`float<class_float>` r, :ref:`float<class_float>` g, :ref:`float<class_float>` b **)**
Constructs a color from an RGB profile using values between 0 and 1 (float). Alpha will always be 1.
::
var c = Color(0.2, 1.0, .7) # a color of an RGBA(51, 255, 178, 255)
.. _class_Color_Color:
- :ref:`Color<class_color>` **Color** **(** :ref:`int<class_int>` from **)**
Constructs a color from a 32-bit integer (each byte represents a component of the RGBA profile).
::
var c = Color(274) # a color of an RGBA(0, 0, 1, 18)
.. _class_Color_Color:
- :ref:`Color<class_color>` **Color** **(** :ref:`String<class_string>` from **)**
Constructs a color from an HTML hexadecimal color string in ARGB or RGB format. See also :ref:`@GDScript.ColorN<class_@GDScript_ColorN>`.
The following string formats are supported:
``"#ff00ff00"`` - ARGB format with '#'
``"ff00ff00"`` - ARGB format
``"#ff00ff"`` - RGB format with '#'
``"ff00ff"`` - RGB format
::
# The following code creates the same color of an RGBA(178, 217, 10, 255)
var c1 = Color("#ffb2d90a") # ARGB format with '#'
var c2 = Color("ffb2d90a") # ARGB format
var c3 = Color("#b2d90a") # RGB format with '#'
var c4 = Color("b2d90a") # RGB format
.. _class_Color_blend:
- :ref:`Color<class_color>` **blend** **(** :ref:`Color<class_color>` over **)**
Returns a new color resulting from blending this color over another color. If the color is opaque, the result would also be opaque. The other color could then take a range of values with different alpha values.
::
var bg = Color(0.0, 1.0, 0.0, 0.5) # Green with alpha of 50%
var fg = Color(1.0, 0.0, 0.0, .5) # Red with alpha of 50%
var blendedColor = bg.blend(fg) # Brown with alpha of 75%
.. _class_Color_contrasted:
- :ref:`Color<class_color>` **contrasted** **(** **)**
Returns the most contrasting color.
::
var c = Color(.3, .4, .9)
var contrastedColor = c.contrasted() # a color of an RGBA(204, 229, 102, 255)
.. _class_Color_darkened:
- :ref:`Color<class_color>` **darkened** **(** :ref:`float<class_float>` amount **)**
Returns a new color resulting from making this color darker by the specified percentage (0-1).
::
var green = Color(0.0, 1.0, 0.0)
var darkgreen = green.darkened(0.2) # 20% darker than regular green
.. _class_Color_gray:
- :ref:`float<class_float>` **gray** **(** **)**
Returns the color's grayscale.
The gray is calculated by (r + g + b) / 3.
::
var c = Color(0.2, 0.45, 0.82)
var gray = c.gray() # a value of 0.466667
.. _class_Color_inverted:
- :ref:`Color<class_color>` **inverted** **(** **)**
Returns the inverted color (1-r, 1-g, 1-b, 1-a).
::
var c = Color(.3, .4, .9)
var invertedColor = c.inverted() # a color of an RGBA(178, 153, 26, 255)
.. _class_Color_lightened:
- :ref:`Color<class_color>` **lightened** **(** :ref:`float<class_float>` amount **)**
Returns a new color resulting from making this color lighter by the specified percentage (0-1).
::
var green = Color(0.0, 1.0, 0.0)
var lightgreen = green.lightened(0.2) # 20% lighter than regular green
.. _class_Color_linear_interpolate:
- :ref:`Color<class_color>` **linear_interpolate** **(** :ref:`Color<class_color>` b, :ref:`float<class_float>` t **)**
Returns the color of the linear interpolation with another color. The value t is between 0 and 1 (float).
::
var c1 = Color(1.0, 0.0, 0.0)
var c2 = Color(0.0, 1.0, 0.0)
var li_c = c1.linear_interpolate(c2, 0.5) # a color of an RGBA(128, 128, 0, 255)
.. _class_Color_to_argb32:
- :ref:`int<class_int>` **to_argb32** **(** **)**
Returns the color's 32-bit integer in ARGB format (each byte represents a component of the ARGB profile). More compatible with DirectX.
::
var c = Color(1, .5, .2)
print(str(c.to_32())) # prints 4294934323
.. _class_Color_to_html:
- :ref:`String<class_string>` **to_html** **(** :ref:`bool<class_bool>` with_alpha=True **)**
Returns the color's HTML hexadecimal color string in ARGB format (ex: ``ff34f822``).
Optionally flag 'false' to not include alpha in hexadecimal string.
::
var c = Color(1, 1, 1, .5)
var s1 = c.to_html() # Results "7fffffff"
var s2 = c.to_html(false) # Results 'ffffff'
.. _class_Color_to_rgba32:
- :ref:`int<class_int>` **to_rgba32** **(** **)**
Returns the color's 32-bit integer in ARGB format (each byte represents a component of the ARGB profile).
::
var c = Color(1, .5, .2)
print(str(c.to_32())) # prints 4294934323
*This is same as :ref:`to_argb32<class_Color_to_argb32>` but may be changed later to support RGBA format instead*.