class_gradient.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/4.2/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.2/doc/classes/Gradient.xml.
  6. .. _class_Gradient:
  7. Gradient
  8. ========
  9. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. A color transition.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. This resource describes a color transition by defining a set of colored points and how to interpolate between them.
  15. See also :ref:`Curve<class_Curve>` which supports more complex easing methods, but does not support colors.
  16. .. rst-class:: classref-reftable-group
  17. Properties
  18. ----------
  19. .. table::
  20. :widths: auto
  21. +-----------------------------------------------------------+-------------------------------------------------------------------------------------+----------------------------------------------+
  22. | :ref:`PackedColorArray<class_PackedColorArray>` | :ref:`colors<class_Gradient_property_colors>` | ``PackedColorArray(0, 0, 0, 1, 1, 1, 1, 1)`` |
  23. +-----------------------------------------------------------+-------------------------------------------------------------------------------------+----------------------------------------------+
  24. | :ref:`ColorSpace<enum_Gradient_ColorSpace>` | :ref:`interpolation_color_space<class_Gradient_property_interpolation_color_space>` | ``0`` |
  25. +-----------------------------------------------------------+-------------------------------------------------------------------------------------+----------------------------------------------+
  26. | :ref:`InterpolationMode<enum_Gradient_InterpolationMode>` | :ref:`interpolation_mode<class_Gradient_property_interpolation_mode>` | ``0`` |
  27. +-----------------------------------------------------------+-------------------------------------------------------------------------------------+----------------------------------------------+
  28. | :ref:`PackedFloat32Array<class_PackedFloat32Array>` | :ref:`offsets<class_Gradient_property_offsets>` | ``PackedFloat32Array(0, 1)`` |
  29. +-----------------------------------------------------------+-------------------------------------------------------------------------------------+----------------------------------------------+
  30. .. rst-class:: classref-reftable-group
  31. Methods
  32. -------
  33. .. table::
  34. :widths: auto
  35. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  36. | void | :ref:`add_point<class_Gradient_method_add_point>` **(** :ref:`float<class_float>` offset, :ref:`Color<class_Color>` color **)** |
  37. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`Color<class_Color>` | :ref:`get_color<class_Gradient_method_get_color>` **(** :ref:`int<class_int>` point **)** |
  39. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`float<class_float>` | :ref:`get_offset<class_Gradient_method_get_offset>` **(** :ref:`int<class_int>` point **)** |
  41. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`int<class_int>` | :ref:`get_point_count<class_Gradient_method_get_point_count>` **(** **)** |const| |
  43. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  44. | void | :ref:`remove_point<class_Gradient_method_remove_point>` **(** :ref:`int<class_int>` point **)** |
  45. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  46. | void | :ref:`reverse<class_Gradient_method_reverse>` **(** **)** |
  47. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`Color<class_Color>` | :ref:`sample<class_Gradient_method_sample>` **(** :ref:`float<class_float>` offset **)** |
  49. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  50. | void | :ref:`set_color<class_Gradient_method_set_color>` **(** :ref:`int<class_int>` point, :ref:`Color<class_Color>` color **)** |
  51. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  52. | void | :ref:`set_offset<class_Gradient_method_set_offset>` **(** :ref:`int<class_int>` point, :ref:`float<class_float>` offset **)** |
  53. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  54. .. rst-class:: classref-section-separator
  55. ----
  56. .. rst-class:: classref-descriptions-group
  57. Enumerations
  58. ------------
  59. .. _enum_Gradient_InterpolationMode:
  60. .. rst-class:: classref-enumeration
  61. enum **InterpolationMode**:
  62. .. _class_Gradient_constant_GRADIENT_INTERPOLATE_LINEAR:
  63. .. rst-class:: classref-enumeration-constant
  64. :ref:`InterpolationMode<enum_Gradient_InterpolationMode>` **GRADIENT_INTERPOLATE_LINEAR** = ``0``
  65. Linear interpolation.
  66. .. _class_Gradient_constant_GRADIENT_INTERPOLATE_CONSTANT:
  67. .. rst-class:: classref-enumeration-constant
  68. :ref:`InterpolationMode<enum_Gradient_InterpolationMode>` **GRADIENT_INTERPOLATE_CONSTANT** = ``1``
  69. Constant interpolation, color changes abruptly at each point and stays uniform between. This might cause visible aliasing when used for a gradient texture in some cases.
  70. .. _class_Gradient_constant_GRADIENT_INTERPOLATE_CUBIC:
  71. .. rst-class:: classref-enumeration-constant
  72. :ref:`InterpolationMode<enum_Gradient_InterpolationMode>` **GRADIENT_INTERPOLATE_CUBIC** = ``2``
  73. Cubic interpolation.
  74. .. rst-class:: classref-item-separator
  75. ----
  76. .. _enum_Gradient_ColorSpace:
  77. .. rst-class:: classref-enumeration
  78. enum **ColorSpace**:
  79. .. _class_Gradient_constant_GRADIENT_COLOR_SPACE_SRGB:
  80. .. rst-class:: classref-enumeration-constant
  81. :ref:`ColorSpace<enum_Gradient_ColorSpace>` **GRADIENT_COLOR_SPACE_SRGB** = ``0``
  82. sRGB color space.
  83. .. _class_Gradient_constant_GRADIENT_COLOR_SPACE_LINEAR_SRGB:
  84. .. rst-class:: classref-enumeration-constant
  85. :ref:`ColorSpace<enum_Gradient_ColorSpace>` **GRADIENT_COLOR_SPACE_LINEAR_SRGB** = ``1``
  86. Linear sRGB color space.
  87. .. _class_Gradient_constant_GRADIENT_COLOR_SPACE_OKLAB:
  88. .. rst-class:: classref-enumeration-constant
  89. :ref:`ColorSpace<enum_Gradient_ColorSpace>` **GRADIENT_COLOR_SPACE_OKLAB** = ``2``
  90. `Oklab <https://bottosson.github.io/posts/oklab/>`__ color space. This color space provides a smooth and uniform-looking transition between colors.
  91. .. rst-class:: classref-section-separator
  92. ----
  93. .. rst-class:: classref-descriptions-group
  94. Property Descriptions
  95. ---------------------
  96. .. _class_Gradient_property_colors:
  97. .. rst-class:: classref-property
  98. :ref:`PackedColorArray<class_PackedColorArray>` **colors** = ``PackedColorArray(0, 0, 0, 1, 1, 1, 1, 1)``
  99. .. rst-class:: classref-property-setget
  100. - void **set_colors** **(** :ref:`PackedColorArray<class_PackedColorArray>` value **)**
  101. - :ref:`PackedColorArray<class_PackedColorArray>` **get_colors** **(** **)**
  102. Gradient's colors returned as a :ref:`PackedColorArray<class_PackedColorArray>`.
  103. \ **Note:** This property returns a copy, modifying the return value does not update the gradient. To update the gradient use :ref:`set_color<class_Gradient_method_set_color>` method (for updating colors individually) or assign to this property directly (for bulk-updating all colors at once).
  104. .. rst-class:: classref-item-separator
  105. ----
  106. .. _class_Gradient_property_interpolation_color_space:
  107. .. rst-class:: classref-property
  108. :ref:`ColorSpace<enum_Gradient_ColorSpace>` **interpolation_color_space** = ``0``
  109. .. rst-class:: classref-property-setget
  110. - void **set_interpolation_color_space** **(** :ref:`ColorSpace<enum_Gradient_ColorSpace>` value **)**
  111. - :ref:`ColorSpace<enum_Gradient_ColorSpace>` **get_interpolation_color_space** **(** **)**
  112. The color space used to interpolate between points of the gradient. It does not affect the returned colors, which will always be in sRGB space. See :ref:`ColorSpace<enum_Gradient_ColorSpace>` for available modes.
  113. \ **Note:** This setting has no effect when :ref:`interpolation_mode<class_Gradient_property_interpolation_mode>` is set to :ref:`GRADIENT_INTERPOLATE_CONSTANT<class_Gradient_constant_GRADIENT_INTERPOLATE_CONSTANT>`.
  114. .. rst-class:: classref-item-separator
  115. ----
  116. .. _class_Gradient_property_interpolation_mode:
  117. .. rst-class:: classref-property
  118. :ref:`InterpolationMode<enum_Gradient_InterpolationMode>` **interpolation_mode** = ``0``
  119. .. rst-class:: classref-property-setget
  120. - void **set_interpolation_mode** **(** :ref:`InterpolationMode<enum_Gradient_InterpolationMode>` value **)**
  121. - :ref:`InterpolationMode<enum_Gradient_InterpolationMode>` **get_interpolation_mode** **(** **)**
  122. The algorithm used to interpolate between points of the gradient. See :ref:`InterpolationMode<enum_Gradient_InterpolationMode>` for available modes.
  123. .. rst-class:: classref-item-separator
  124. ----
  125. .. _class_Gradient_property_offsets:
  126. .. rst-class:: classref-property
  127. :ref:`PackedFloat32Array<class_PackedFloat32Array>` **offsets** = ``PackedFloat32Array(0, 1)``
  128. .. rst-class:: classref-property-setget
  129. - void **set_offsets** **(** :ref:`PackedFloat32Array<class_PackedFloat32Array>` value **)**
  130. - :ref:`PackedFloat32Array<class_PackedFloat32Array>` **get_offsets** **(** **)**
  131. Gradient's offsets returned as a :ref:`PackedFloat32Array<class_PackedFloat32Array>`.
  132. \ **Note:** This property returns a copy, modifying the return value does not update the gradient. To update the gradient use :ref:`set_offset<class_Gradient_method_set_offset>` method (for updating offsets individually) or assign to this property directly (for bulk-updating all offsets at once).
  133. .. rst-class:: classref-section-separator
  134. ----
  135. .. rst-class:: classref-descriptions-group
  136. Method Descriptions
  137. -------------------
  138. .. _class_Gradient_method_add_point:
  139. .. rst-class:: classref-method
  140. void **add_point** **(** :ref:`float<class_float>` offset, :ref:`Color<class_Color>` color **)**
  141. Adds the specified color to the gradient, with the specified offset.
  142. .. rst-class:: classref-item-separator
  143. ----
  144. .. _class_Gradient_method_get_color:
  145. .. rst-class:: classref-method
  146. :ref:`Color<class_Color>` **get_color** **(** :ref:`int<class_int>` point **)**
  147. Returns the color of the gradient color at index ``point``.
  148. .. rst-class:: classref-item-separator
  149. ----
  150. .. _class_Gradient_method_get_offset:
  151. .. rst-class:: classref-method
  152. :ref:`float<class_float>` **get_offset** **(** :ref:`int<class_int>` point **)**
  153. Returns the offset of the gradient color at index ``point``.
  154. .. rst-class:: classref-item-separator
  155. ----
  156. .. _class_Gradient_method_get_point_count:
  157. .. rst-class:: classref-method
  158. :ref:`int<class_int>` **get_point_count** **(** **)** |const|
  159. Returns the number of colors in the gradient.
  160. .. rst-class:: classref-item-separator
  161. ----
  162. .. _class_Gradient_method_remove_point:
  163. .. rst-class:: classref-method
  164. void **remove_point** **(** :ref:`int<class_int>` point **)**
  165. Removes the color at index ``point``.
  166. .. rst-class:: classref-item-separator
  167. ----
  168. .. _class_Gradient_method_reverse:
  169. .. rst-class:: classref-method
  170. void **reverse** **(** **)**
  171. Reverses/mirrors the gradient.
  172. \ **Note:** This method mirrors all points around the middle of the gradient, which may produce unexpected results when :ref:`interpolation_mode<class_Gradient_property_interpolation_mode>` is set to :ref:`GRADIENT_INTERPOLATE_CONSTANT<class_Gradient_constant_GRADIENT_INTERPOLATE_CONSTANT>`.
  173. .. rst-class:: classref-item-separator
  174. ----
  175. .. _class_Gradient_method_sample:
  176. .. rst-class:: classref-method
  177. :ref:`Color<class_Color>` **sample** **(** :ref:`float<class_float>` offset **)**
  178. Returns the interpolated color specified by ``offset``.
  179. .. rst-class:: classref-item-separator
  180. ----
  181. .. _class_Gradient_method_set_color:
  182. .. rst-class:: classref-method
  183. void **set_color** **(** :ref:`int<class_int>` point, :ref:`Color<class_Color>` color **)**
  184. Sets the color of the gradient color at index ``point``.
  185. .. rst-class:: classref-item-separator
  186. ----
  187. .. _class_Gradient_method_set_offset:
  188. .. rst-class:: classref-method
  189. void **set_offset** **(** :ref:`int<class_int>` point, :ref:`float<class_float>` offset **)**
  190. Sets the offset for the gradient color at index ``point``.
  191. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  192. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  193. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  194. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  195. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  196. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  197. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`