class_gradient.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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.0/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.0/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 interpolator resource which can be used to generate colors between user-defined color points.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Given a set of colors, this resource will interpolate them in order. This means that if you have color 1, color 2 and color 3, the gradient will interpolate from color 1 to color 2 and from color 2 to color 3. The gradient will initially have 2 colors (black and white), one (black) at gradient lower offset 0 and the other (white) at the gradient higher offset 1.
  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:`InterpolationMode<enum_Gradient_InterpolationMode>` | :ref:`interpolation_mode<class_Gradient_property_interpolation_mode>` | ``0`` |
  25. +-----------------------------------------------------------+-----------------------------------------------------------------------+----------------------------------------------+
  26. | :ref:`PackedFloat32Array<class_PackedFloat32Array>` | :ref:`offsets<class_Gradient_property_offsets>` | ``PackedFloat32Array(0, 1)`` |
  27. +-----------------------------------------------------------+-----------------------------------------------------------------------+----------------------------------------------+
  28. .. rst-class:: classref-reftable-group
  29. Methods
  30. -------
  31. .. table::
  32. :widths: auto
  33. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  34. | void | :ref:`add_point<class_Gradient_method_add_point>` **(** :ref:`float<class_float>` offset, :ref:`Color<class_Color>` color **)** |
  35. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`Color<class_Color>` | :ref:`get_color<class_Gradient_method_get_color>` **(** :ref:`int<class_int>` point **)** |
  37. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`float<class_float>` | :ref:`get_offset<class_Gradient_method_get_offset>` **(** :ref:`int<class_int>` point **)** |
  39. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`int<class_int>` | :ref:`get_point_count<class_Gradient_method_get_point_count>` **(** **)** |const| |
  41. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  42. | void | :ref:`remove_point<class_Gradient_method_remove_point>` **(** :ref:`int<class_int>` point **)** |
  43. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  44. | void | :ref:`reverse<class_Gradient_method_reverse>` **(** **)** |
  45. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`Color<class_Color>` | :ref:`sample<class_Gradient_method_sample>` **(** :ref:`float<class_float>` offset **)** |
  47. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  48. | void | :ref:`set_color<class_Gradient_method_set_color>` **(** :ref:`int<class_int>` point, :ref:`Color<class_Color>` color **)** |
  49. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  50. | void | :ref:`set_offset<class_Gradient_method_set_offset>` **(** :ref:`int<class_int>` point, :ref:`float<class_float>` offset **)** |
  51. +---------------------------+---------------------------------------------------------------------------------------------------------------------------------+
  52. .. rst-class:: classref-section-separator
  53. ----
  54. .. rst-class:: classref-descriptions-group
  55. Enumerations
  56. ------------
  57. .. _enum_Gradient_InterpolationMode:
  58. .. rst-class:: classref-enumeration
  59. enum **InterpolationMode**:
  60. .. _class_Gradient_constant_GRADIENT_INTERPOLATE_LINEAR:
  61. .. rst-class:: classref-enumeration-constant
  62. :ref:`InterpolationMode<enum_Gradient_InterpolationMode>` **GRADIENT_INTERPOLATE_LINEAR** = ``0``
  63. Linear interpolation.
  64. .. _class_Gradient_constant_GRADIENT_INTERPOLATE_CONSTANT:
  65. .. rst-class:: classref-enumeration-constant
  66. :ref:`InterpolationMode<enum_Gradient_InterpolationMode>` **GRADIENT_INTERPOLATE_CONSTANT** = ``1``
  67. 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.
  68. .. _class_Gradient_constant_GRADIENT_INTERPOLATE_CUBIC:
  69. .. rst-class:: classref-enumeration-constant
  70. :ref:`InterpolationMode<enum_Gradient_InterpolationMode>` **GRADIENT_INTERPOLATE_CUBIC** = ``2``
  71. Cubic interpolation.
  72. .. rst-class:: classref-section-separator
  73. ----
  74. .. rst-class:: classref-descriptions-group
  75. Property Descriptions
  76. ---------------------
  77. .. _class_Gradient_property_colors:
  78. .. rst-class:: classref-property
  79. :ref:`PackedColorArray<class_PackedColorArray>` **colors** = ``PackedColorArray(0, 0, 0, 1, 1, 1, 1, 1)``
  80. .. rst-class:: classref-property-setget
  81. - void **set_colors** **(** :ref:`PackedColorArray<class_PackedColorArray>` value **)**
  82. - :ref:`PackedColorArray<class_PackedColorArray>` **get_colors** **(** **)**
  83. Gradient's colors returned as a :ref:`PackedColorArray<class_PackedColorArray>`.
  84. .. rst-class:: classref-item-separator
  85. ----
  86. .. _class_Gradient_property_interpolation_mode:
  87. .. rst-class:: classref-property
  88. :ref:`InterpolationMode<enum_Gradient_InterpolationMode>` **interpolation_mode** = ``0``
  89. .. rst-class:: classref-property-setget
  90. - void **set_interpolation_mode** **(** :ref:`InterpolationMode<enum_Gradient_InterpolationMode>` value **)**
  91. - :ref:`InterpolationMode<enum_Gradient_InterpolationMode>` **get_interpolation_mode** **(** **)**
  92. Defines how the colors between points of the gradient are interpolated. See :ref:`InterpolationMode<enum_Gradient_InterpolationMode>` for available modes.
  93. .. rst-class:: classref-item-separator
  94. ----
  95. .. _class_Gradient_property_offsets:
  96. .. rst-class:: classref-property
  97. :ref:`PackedFloat32Array<class_PackedFloat32Array>` **offsets** = ``PackedFloat32Array(0, 1)``
  98. .. rst-class:: classref-property-setget
  99. - void **set_offsets** **(** :ref:`PackedFloat32Array<class_PackedFloat32Array>` value **)**
  100. - :ref:`PackedFloat32Array<class_PackedFloat32Array>` **get_offsets** **(** **)**
  101. Gradient's offsets returned as a :ref:`PackedFloat32Array<class_PackedFloat32Array>`.
  102. .. rst-class:: classref-section-separator
  103. ----
  104. .. rst-class:: classref-descriptions-group
  105. Method Descriptions
  106. -------------------
  107. .. _class_Gradient_method_add_point:
  108. .. rst-class:: classref-method
  109. void **add_point** **(** :ref:`float<class_float>` offset, :ref:`Color<class_Color>` color **)**
  110. Adds the specified color to the end of the gradient, with the specified offset.
  111. .. rst-class:: classref-item-separator
  112. ----
  113. .. _class_Gradient_method_get_color:
  114. .. rst-class:: classref-method
  115. :ref:`Color<class_Color>` **get_color** **(** :ref:`int<class_int>` point **)**
  116. Returns the color of the gradient color at index ``point``.
  117. .. rst-class:: classref-item-separator
  118. ----
  119. .. _class_Gradient_method_get_offset:
  120. .. rst-class:: classref-method
  121. :ref:`float<class_float>` **get_offset** **(** :ref:`int<class_int>` point **)**
  122. Returns the offset of the gradient color at index ``point``.
  123. .. rst-class:: classref-item-separator
  124. ----
  125. .. _class_Gradient_method_get_point_count:
  126. .. rst-class:: classref-method
  127. :ref:`int<class_int>` **get_point_count** **(** **)** |const|
  128. Returns the number of colors in the gradient.
  129. .. rst-class:: classref-item-separator
  130. ----
  131. .. _class_Gradient_method_remove_point:
  132. .. rst-class:: classref-method
  133. void **remove_point** **(** :ref:`int<class_int>` point **)**
  134. Removes the color at the index ``point``.
  135. .. rst-class:: classref-item-separator
  136. ----
  137. .. _class_Gradient_method_reverse:
  138. .. rst-class:: classref-method
  139. void **reverse** **(** **)**
  140. Reverses/mirrors the gradient.
  141. \ **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>`.
  142. .. rst-class:: classref-item-separator
  143. ----
  144. .. _class_Gradient_method_sample:
  145. .. rst-class:: classref-method
  146. :ref:`Color<class_Color>` **sample** **(** :ref:`float<class_float>` offset **)**
  147. Returns the interpolated color specified by ``offset``.
  148. .. rst-class:: classref-item-separator
  149. ----
  150. .. _class_Gradient_method_set_color:
  151. .. rst-class:: classref-method
  152. void **set_color** **(** :ref:`int<class_int>` point, :ref:`Color<class_Color>` color **)**
  153. Sets the color of the gradient color at index ``point``.
  154. .. rst-class:: classref-item-separator
  155. ----
  156. .. _class_Gradient_method_set_offset:
  157. .. rst-class:: classref-method
  158. void **set_offset** **(** :ref:`int<class_int>` point, :ref:`float<class_float>` offset **)**
  159. Sets the offset for the gradient color at index ``point``.
  160. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  161. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  162. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  163. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  164. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  165. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`