class_color.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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:`float<class_float>` | :ref:`gray<class_Color_gray>` **(** **)** |
  27. +------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`Color<class_color>` | :ref:`inverted<class_Color_inverted>` **(** **)** |
  29. +------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`Color<class_color>` | :ref:`linear_interpolate<class_Color_linear_interpolate>` **(** :ref:`Color<class_color>` b, :ref:`float<class_float>` t **)** |
  31. +------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`int<class_int>` | :ref:`to_argb32<class_Color_to_argb32>` **(** **)** |
  33. +------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`String<class_string>` | :ref:`to_html<class_Color_to_html>` **(** :ref:`bool<class_bool>` with_alpha=True **)** |
  35. +------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`int<class_int>` | :ref:`to_rgba32<class_Color_to_rgba32>` **(** **)** |
  37. +------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. Member Variables
  39. ----------------
  40. - :ref:`float<class_float>` **a** - Alpha (0 to 1)
  41. - :ref:`int<class_int>` **a8** - Alpha (0 to 255)
  42. - :ref:`float<class_float>` **b** - Blue (0 to 1)
  43. - :ref:`int<class_int>` **b8** - Blue (0 to 255)
  44. - :ref:`float<class_float>` **g** - Green (0 to 1)
  45. - :ref:`int<class_int>` **g8** - Green (0 to 255)
  46. - :ref:`float<class_float>` **h** - Hue (0 to 1)
  47. - :ref:`float<class_float>` **r** - Red (0 to 1)
  48. - :ref:`int<class_int>` **r8** - Red (0 to 255)
  49. - :ref:`float<class_float>` **s** - Saturation (0 to 1)
  50. - :ref:`float<class_float>` **v** - Value (0 to 1)
  51. Description
  52. -----------
  53. 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.
  54. Member Function Description
  55. ---------------------------
  56. .. _class_Color_Color:
  57. - :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 **)**
  58. Constructs a color from an RGBA profile using values between 0 and 1 (float).
  59. ::
  60. var c = Color(0.2, 1.0, .7, .8) # a color of an RGBA(51, 255, 178, 204)
  61. .. _class_Color_Color:
  62. - :ref:`Color<class_color>` **Color** **(** :ref:`float<class_float>` r, :ref:`float<class_float>` g, :ref:`float<class_float>` b **)**
  63. Constructs a color from an RGB profile using values between 0 and 1 (float). Alpha will always be 1.
  64. ::
  65. var c = Color(0.2, 1.0, .7) # a color of an RGBA(51, 255, 178, 255)
  66. .. _class_Color_Color:
  67. - :ref:`Color<class_color>` **Color** **(** :ref:`int<class_int>` from **)**
  68. Constructs a color from a 32-bit integer (each byte represents a component of the RGBA profile).
  69. ::
  70. var c = Color(274) # a color of an RGBA(0, 0, 1, 18)
  71. .. _class_Color_Color:
  72. - :ref:`Color<class_color>` **Color** **(** :ref:`String<class_string>` from **)**
  73. Constructs a color from an HTML hexadecimal color string in ARGB or RGB format.
  74. The following string formats are supported:
  75. ``"#ff00ff00"`` - ARGB format with '#'
  76. ``"ff00ff00"`` - ARGB format
  77. ``"#ff00ff"`` - RGB format with '#'
  78. ``"ff00ff"`` - RGB format
  79. ::
  80. # The following code creates the same color of an RGBA(178, 217, 10, 255)
  81. var c1 = Color("#ffb2d90a") # ARGB format with '#'
  82. var c2 = Color("ffb2d90a") # ARGB format
  83. var c3 = Color("#b2d90a") # RGB format with '#'
  84. var c4 = Color("b2d90a") # RGB format
  85. .. _class_Color_blend:
  86. - :ref:`Color<class_color>` **blend** **(** :ref:`Color<class_color>` over **)**
  87. 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.
  88. ::
  89. var bg = Color(0.0, 1.0, 0.0, 0.5) # Green with alpha of 50%
  90. var fg = Color(1.0, 0.0, 0.0, .5) # Red with alpha of 50%
  91. var blendedColor = bg.blend(fg) # Brown with alpha of 75%
  92. .. _class_Color_contrasted:
  93. - :ref:`Color<class_color>` **contrasted** **(** **)**
  94. Returns the most contrasting color.
  95. ::
  96. var c = Color(.3, .4, .9)
  97. var contrastedColor = c.contrasted() # a color of an RGBA(204, 229, 102, 255)
  98. .. _class_Color_gray:
  99. - :ref:`float<class_float>` **gray** **(** **)**
  100. Returns the color's grayscale.
  101. The gray is calculated by (r + g + b) / 3.
  102. ::
  103. var c = Color(0.2, 0.45, 0.82)
  104. var gray = c.gray() # a value of 0.466667
  105. .. _class_Color_inverted:
  106. - :ref:`Color<class_color>` **inverted** **(** **)**
  107. Returns the inverted color (1-r, 1-g, 1-b, 1-a).
  108. ::
  109. var c = Color(.3, .4, .9)
  110. var invertedColor = c.inverted() # a color of an RGBA(178, 153, 26, 255)
  111. .. _class_Color_linear_interpolate:
  112. - :ref:`Color<class_color>` **linear_interpolate** **(** :ref:`Color<class_color>` b, :ref:`float<class_float>` t **)**
  113. Returns the color of the linear interpolation with another color. The value t is between 0 and 1 (float).
  114. ::
  115. var c1 = Color(1.0, 0.0, 0.0)
  116. var c2 = Color(0.0, 1.0, 0.0)
  117. var li_c = c1.linear_interpolate(c2, 0.5) # a color of an RGBA(128, 128, 0, 255)
  118. .. _class_Color_to_argb32:
  119. - :ref:`int<class_int>` **to_argb32** **(** **)**
  120. Returns the color's 32-bit integer in ARGB format (each byte represents a component of the ARGB profile). More compatible with DirectX.
  121. ::
  122. var c = Color(1, .5, .2)
  123. print(str(c.to_32())) # prints 4294934323
  124. .. _class_Color_to_html:
  125. - :ref:`String<class_string>` **to_html** **(** :ref:`bool<class_bool>` with_alpha=True **)**
  126. Returns the color's HTML hexadecimal color string in ARGB format (ex: ``ff34f822``).
  127. Optionally flag 'false' to not include alpha in hexadecimal string.
  128. ::
  129. var c = Color(1, 1, 1, .5)
  130. var s1 = c.to_html() # Results "7fffffff"
  131. var s2 = c.to_html(false) # Results 'ffffff'
  132. .. _class_Color_to_rgba32:
  133. - :ref:`int<class_int>` **to_rgba32** **(** **)**
  134. Returns the color's 32-bit integer in ARGB format (each byte represents a component of the ARGB profile).
  135. ::
  136. var c = Color(1, .5, .2)
  137. print(str(c.to_32())) # prints 4294934323
  138. *This is same as :ref:`to_ARGB32<class_Color_to_ARGB32>` but may be changed later to support RGBA format instead*.