class_color.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the Color.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_Color:
  5. Color
  6. =====
  7. **Category:** Built-In Types
  8. Brief Description
  9. -----------------
  10. Color in RGBA format with some support for ARGB format.
  11. Member Functions
  12. ----------------
  13. +------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  14. | :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 **)** |
  15. +------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  16. | :ref:`Color<class_color>` | :ref:`Color<class_Color_Color>` **(** :ref:`float<class_float>` r, :ref:`float<class_float>` g, :ref:`float<class_float>` b **)** |
  17. +------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | :ref:`Color<class_color>` | :ref:`Color<class_Color_Color>` **(** :ref:`int<class_int>` from **)** |
  19. +------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`Color<class_color>` | :ref:`Color<class_Color_Color>` **(** :ref:`String<class_string>` from **)** |
  21. +------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`Color<class_color>` | :ref:`blend<class_Color_blend>` **(** :ref:`Color<class_color>` over **)** |
  23. +------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`Color<class_color>` | :ref:`contrasted<class_Color_contrasted>` **(** **)** |
  25. +------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`Color<class_color>` | :ref:`darkened<class_Color_darkened>` **(** :ref:`float<class_float>` amount **)** |
  27. +------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`float<class_float>` | :ref:`gray<class_Color_gray>` **(** **)** |
  29. +------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`Color<class_color>` | :ref:`inverted<class_Color_inverted>` **(** **)** |
  31. +------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`Color<class_color>` | :ref:`lightened<class_Color_lightened>` **(** :ref:`float<class_float>` amount **)** |
  33. +------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`Color<class_color>` | :ref:`linear_interpolate<class_Color_linear_interpolate>` **(** :ref:`Color<class_color>` b, :ref:`float<class_float>` t **)** |
  35. +------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`int<class_int>` | :ref:`to_argb32<class_Color_to_argb32>` **(** **)** |
  37. +------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`String<class_string>` | :ref:`to_html<class_Color_to_html>` **(** :ref:`bool<class_bool>` with_alpha=True **)** |
  39. +------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`int<class_int>` | :ref:`to_rgba32<class_Color_to_rgba32>` **(** **)** |
  41. +------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. Member Variables
  43. ----------------
  44. .. _class_Color_a:
  45. - :ref:`float<class_float>` **a** - Alpha (0 to 1)
  46. .. _class_Color_a8:
  47. - :ref:`int<class_int>` **a8** - Alpha (0 to 255)
  48. .. _class_Color_b:
  49. - :ref:`float<class_float>` **b** - Blue (0 to 1)
  50. .. _class_Color_b8:
  51. - :ref:`int<class_int>` **b8** - Blue (0 to 255)
  52. .. _class_Color_g:
  53. - :ref:`float<class_float>` **g** - Green (0 to 1)
  54. .. _class_Color_g8:
  55. - :ref:`int<class_int>` **g8** - Green (0 to 255)
  56. .. _class_Color_h:
  57. - :ref:`float<class_float>` **h** - Hue (0 to 1)
  58. .. _class_Color_r:
  59. - :ref:`float<class_float>` **r** - Red (0 to 1)
  60. .. _class_Color_r8:
  61. - :ref:`int<class_int>` **r8** - Red (0 to 255)
  62. .. _class_Color_s:
  63. - :ref:`float<class_float>` **s** - Saturation (0 to 1)
  64. .. _class_Color_v:
  65. - :ref:`float<class_float>` **v** - Value (0 to 1)
  66. Description
  67. -----------
  68. 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.
  69. You can also create a color from standardised color names with :ref:`@GDScript.ColorN<class_@GDScript_ColorN>`.
  70. Member Function Description
  71. ---------------------------
  72. .. _class_Color_Color:
  73. - :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 **)**
  74. Constructs a color from an RGBA profile using values between 0 and 1 (float).
  75. ::
  76. var c = Color(0.2, 1.0, .7, .8) # a color of an RGBA(51, 255, 178, 204)
  77. .. _class_Color_Color:
  78. - :ref:`Color<class_color>` **Color** **(** :ref:`float<class_float>` r, :ref:`float<class_float>` g, :ref:`float<class_float>` b **)**
  79. Constructs a color from an RGB profile using values between 0 and 1 (float). Alpha will always be 1.
  80. ::
  81. var c = Color(0.2, 1.0, .7) # a color of an RGBA(51, 255, 178, 255)
  82. .. _class_Color_Color:
  83. - :ref:`Color<class_color>` **Color** **(** :ref:`int<class_int>` from **)**
  84. Constructs a color from a 32-bit integer (each byte represents a component of the RGBA profile).
  85. ::
  86. var c = Color(274) # a color of an RGBA(0, 0, 1, 18)
  87. .. _class_Color_Color:
  88. - :ref:`Color<class_color>` **Color** **(** :ref:`String<class_string>` from **)**
  89. Constructs a color from an HTML hexadecimal color string in ARGB or RGB format. See also :ref:`@GDScript.ColorN<class_@GDScript_ColorN>`.
  90. The following string formats are supported:
  91. ``"#ff00ff00"`` - ARGB format with '#'
  92. ``"ff00ff00"`` - ARGB format
  93. ``"#ff00ff"`` - RGB format with '#'
  94. ``"ff00ff"`` - RGB format
  95. ::
  96. # The following code creates the same color of an RGBA(178, 217, 10, 255)
  97. var c1 = Color("#ffb2d90a") # ARGB format with '#'
  98. var c2 = Color("ffb2d90a") # ARGB format
  99. var c3 = Color("#b2d90a") # RGB format with '#'
  100. var c4 = Color("b2d90a") # RGB format
  101. .. _class_Color_blend:
  102. - :ref:`Color<class_color>` **blend** **(** :ref:`Color<class_color>` over **)**
  103. 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.
  104. ::
  105. var bg = Color(0.0, 1.0, 0.0, 0.5) # Green with alpha of 50%
  106. var fg = Color(1.0, 0.0, 0.0, .5) # Red with alpha of 50%
  107. var blendedColor = bg.blend(fg) # Brown with alpha of 75%
  108. .. _class_Color_contrasted:
  109. - :ref:`Color<class_color>` **contrasted** **(** **)**
  110. Returns the most contrasting color.
  111. ::
  112. var c = Color(.3, .4, .9)
  113. var contrastedColor = c.contrasted() # a color of an RGBA(204, 229, 102, 255)
  114. .. _class_Color_darkened:
  115. - :ref:`Color<class_color>` **darkened** **(** :ref:`float<class_float>` amount **)**
  116. Returns a new color resulting from making this color darker by the specified percentage (0-1).
  117. ::
  118. var green = Color(0.0, 1.0, 0.0)
  119. var darkgreen = green.darkened(0.2) # 20% darker than regular green
  120. .. _class_Color_gray:
  121. - :ref:`float<class_float>` **gray** **(** **)**
  122. Returns the color's grayscale.
  123. The gray is calculated by (r + g + b) / 3.
  124. ::
  125. var c = Color(0.2, 0.45, 0.82)
  126. var gray = c.gray() # a value of 0.466667
  127. .. _class_Color_inverted:
  128. - :ref:`Color<class_color>` **inverted** **(** **)**
  129. Returns the inverted color (1-r, 1-g, 1-b, 1-a).
  130. ::
  131. var c = Color(.3, .4, .9)
  132. var invertedColor = c.inverted() # a color of an RGBA(178, 153, 26, 255)
  133. .. _class_Color_lightened:
  134. - :ref:`Color<class_color>` **lightened** **(** :ref:`float<class_float>` amount **)**
  135. Returns a new color resulting from making this color lighter by the specified percentage (0-1).
  136. ::
  137. var green = Color(0.0, 1.0, 0.0)
  138. var lightgreen = green.lightened(0.2) # 20% lighter than regular green
  139. .. _class_Color_linear_interpolate:
  140. - :ref:`Color<class_color>` **linear_interpolate** **(** :ref:`Color<class_color>` b, :ref:`float<class_float>` t **)**
  141. Returns the color of the linear interpolation with another color. The value t is between 0 and 1 (float).
  142. ::
  143. var c1 = Color(1.0, 0.0, 0.0)
  144. var c2 = Color(0.0, 1.0, 0.0)
  145. var li_c = c1.linear_interpolate(c2, 0.5) # a color of an RGBA(128, 128, 0, 255)
  146. .. _class_Color_to_argb32:
  147. - :ref:`int<class_int>` **to_argb32** **(** **)**
  148. Returns the color's 32-bit integer in ARGB format (each byte represents a component of the ARGB profile). More compatible with DirectX.
  149. ::
  150. var c = Color(1, .5, .2)
  151. print(str(c.to_32())) # prints 4294934323
  152. .. _class_Color_to_html:
  153. - :ref:`String<class_string>` **to_html** **(** :ref:`bool<class_bool>` with_alpha=True **)**
  154. Returns the color's HTML hexadecimal color string in ARGB format (ex: ``ff34f822``).
  155. Optionally flag 'false' to not include alpha in hexadecimal string.
  156. ::
  157. var c = Color(1, 1, 1, .5)
  158. var s1 = c.to_html() # Results "7fffffff"
  159. var s2 = c.to_html(false) # Results 'ffffff'
  160. .. _class_Color_to_rgba32:
  161. - :ref:`int<class_int>` **to_rgba32** **(** **)**
  162. Returns the color's 32-bit integer in ARGB format (each byte represents a component of the ARGB profile).
  163. ::
  164. var c = Color(1, .5, .2)
  165. print(str(c.to_32())) # prints 4294934323
  166. *This is same as :ref:`to_argb32<class_Color_to_argb32>` but may be changed later to support RGBA format instead*.