class_color.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. Member Function Description
  70. ---------------------------
  71. .. _class_Color_Color:
  72. - :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 **)**
  73. Constructs a color from an RGBA profile using values between 0 and 1 (float).
  74. ::
  75. var c = Color(0.2, 1.0, .7, .8) # a color of an RGBA(51, 255, 178, 204)
  76. .. _class_Color_Color:
  77. - :ref:`Color<class_color>` **Color** **(** :ref:`float<class_float>` r, :ref:`float<class_float>` g, :ref:`float<class_float>` b **)**
  78. Constructs a color from an RGB profile using values between 0 and 1 (float). Alpha will always be 1.
  79. ::
  80. var c = Color(0.2, 1.0, .7) # a color of an RGBA(51, 255, 178, 255)
  81. .. _class_Color_Color:
  82. - :ref:`Color<class_color>` **Color** **(** :ref:`int<class_int>` from **)**
  83. Constructs a color from a 32-bit integer (each byte represents a component of the RGBA profile).
  84. ::
  85. var c = Color(274) # a color of an RGBA(0, 0, 1, 18)
  86. .. _class_Color_Color:
  87. - :ref:`Color<class_color>` **Color** **(** :ref:`String<class_string>` from **)**
  88. Constructs a color from an HTML hexadecimal color string in ARGB or RGB format.
  89. The following string formats are supported:
  90. ``"#ff00ff00"`` - ARGB format with '#'
  91. ``"ff00ff00"`` - ARGB format
  92. ``"#ff00ff"`` - RGB format with '#'
  93. ``"ff00ff"`` - RGB format
  94. ::
  95. # The following code creates the same color of an RGBA(178, 217, 10, 255)
  96. var c1 = Color("#ffb2d90a") # ARGB format with '#'
  97. var c2 = Color("ffb2d90a") # ARGB format
  98. var c3 = Color("#b2d90a") # RGB format with '#'
  99. var c4 = Color("b2d90a") # RGB format
  100. .. _class_Color_blend:
  101. - :ref:`Color<class_color>` **blend** **(** :ref:`Color<class_color>` over **)**
  102. 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.
  103. ::
  104. var bg = Color(0.0, 1.0, 0.0, 0.5) # Green with alpha of 50%
  105. var fg = Color(1.0, 0.0, 0.0, .5) # Red with alpha of 50%
  106. var blendedColor = bg.blend(fg) # Brown with alpha of 75%
  107. .. _class_Color_contrasted:
  108. - :ref:`Color<class_color>` **contrasted** **(** **)**
  109. Returns the most contrasting color.
  110. ::
  111. var c = Color(.3, .4, .9)
  112. var contrastedColor = c.contrasted() # a color of an RGBA(204, 229, 102, 255)
  113. .. _class_Color_darkened:
  114. - :ref:`Color<class_color>` **darkened** **(** :ref:`float<class_float>` amount **)**
  115. Returns a new color resulting from making this color darker by the specified percentage (0-1).
  116. ::
  117. var green = Color(0.0, 1.0, 0.0)
  118. var darkgreen = green.darkened(0.2) # 20% darker than regular green
  119. .. _class_Color_gray:
  120. - :ref:`float<class_float>` **gray** **(** **)**
  121. Returns the color's grayscale.
  122. The gray is calculated by (r + g + b) / 3.
  123. ::
  124. var c = Color(0.2, 0.45, 0.82)
  125. var gray = c.gray() # a value of 0.466667
  126. .. _class_Color_inverted:
  127. - :ref:`Color<class_color>` **inverted** **(** **)**
  128. Returns the inverted color (1-r, 1-g, 1-b, 1-a).
  129. ::
  130. var c = Color(.3, .4, .9)
  131. var invertedColor = c.inverted() # a color of an RGBA(178, 153, 26, 255)
  132. .. _class_Color_lightened:
  133. - :ref:`Color<class_color>` **lightened** **(** :ref:`float<class_float>` amount **)**
  134. Returns a new color resulting from making this color lighter by the specified percentage (0-1).
  135. ::
  136. var green = Color(0.0, 1.0, 0.0)
  137. var lightgreen = green.lightened(0.2) # 20% lighter than regular green
  138. .. _class_Color_linear_interpolate:
  139. - :ref:`Color<class_color>` **linear_interpolate** **(** :ref:`Color<class_color>` b, :ref:`float<class_float>` t **)**
  140. Returns the color of the linear interpolation with another color. The value t is between 0 and 1 (float).
  141. ::
  142. var c1 = Color(1.0, 0.0, 0.0)
  143. var c2 = Color(0.0, 1.0, 0.0)
  144. var li_c = c1.linear_interpolate(c2, 0.5) # a color of an RGBA(128, 128, 0, 255)
  145. .. _class_Color_to_argb32:
  146. - :ref:`int<class_int>` **to_argb32** **(** **)**
  147. Returns the color's 32-bit integer in ARGB format (each byte represents a component of the ARGB profile). More compatible with DirectX.
  148. ::
  149. var c = Color(1, .5, .2)
  150. print(str(c.to_32())) # prints 4294934323
  151. .. _class_Color_to_html:
  152. - :ref:`String<class_string>` **to_html** **(** :ref:`bool<class_bool>` with_alpha=True **)**
  153. Returns the color's HTML hexadecimal color string in ARGB format (ex: ``ff34f822``).
  154. Optionally flag 'false' to not include alpha in hexadecimal string.
  155. ::
  156. var c = Color(1, 1, 1, .5)
  157. var s1 = c.to_html() # Results "7fffffff"
  158. var s2 = c.to_html(false) # Results 'ffffff'
  159. .. _class_Color_to_rgba32:
  160. - :ref:`int<class_int>` **to_rgba32** **(** **)**
  161. Returns the color's 32-bit integer in ARGB format (each byte represents a component of the ARGB profile).
  162. ::
  163. var c = Color(1, .5, .2)
  164. print(str(c.to_32())) # prints 4294934323
  165. *This is same as :ref:`to_ARGB32<class_Color_to_ARGB32>` but may be changed later to support RGBA format instead*.