Files
godot-docs/classes/class_gradient.rst
2025-10-11 03:22:24 +00:00

352 lines
15 KiB
ReStructuredText

:github_url: hide
.. DO NOT EDIT THIS FILE!!!
.. Generated automatically from Godot engine sources.
.. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
.. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Gradient.xml.
.. _class_Gradient:
Gradient
========
**Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
A color transition.
.. rst-class:: classref-introduction-group
Description
-----------
This resource describes a color transition by defining a set of colored points and how to interpolate between them.
See also :ref:`Curve<class_Curve>` which supports more complex easing methods, but does not support colors.
.. rst-class:: classref-reftable-group
Properties
----------
.. table::
:widths: auto
+-----------------------------------------------------------+-------------------------------------------------------------------------------------+----------------------------------------------+
| :ref:`PackedColorArray<class_PackedColorArray>` | :ref:`colors<class_Gradient_property_colors>` | ``PackedColorArray(0, 0, 0, 1, 1, 1, 1, 1)`` |
+-----------------------------------------------------------+-------------------------------------------------------------------------------------+----------------------------------------------+
| :ref:`ColorSpace<enum_Gradient_ColorSpace>` | :ref:`interpolation_color_space<class_Gradient_property_interpolation_color_space>` | ``0`` |
+-----------------------------------------------------------+-------------------------------------------------------------------------------------+----------------------------------------------+
| :ref:`InterpolationMode<enum_Gradient_InterpolationMode>` | :ref:`interpolation_mode<class_Gradient_property_interpolation_mode>` | ``0`` |
+-----------------------------------------------------------+-------------------------------------------------------------------------------------+----------------------------------------------+
| :ref:`PackedFloat32Array<class_PackedFloat32Array>` | :ref:`offsets<class_Gradient_property_offsets>` | ``PackedFloat32Array(0, 1)`` |
+-----------------------------------------------------------+-------------------------------------------------------------------------------------+----------------------------------------------+
.. rst-class:: classref-reftable-group
Methods
-------
.. table::
:widths: auto
+---------------------------+--------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`add_point<class_Gradient_method_add_point>`\ (\ offset\: :ref:`float<class_float>`, color\: :ref:`Color<class_Color>`\ ) |
+---------------------------+--------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Color<class_Color>` | :ref:`get_color<class_Gradient_method_get_color>`\ (\ point\: :ref:`int<class_int>`\ ) |
+---------------------------+--------------------------------------------------------------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`get_offset<class_Gradient_method_get_offset>`\ (\ point\: :ref:`int<class_int>`\ ) |
+---------------------------+--------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`get_point_count<class_Gradient_method_get_point_count>`\ (\ ) |const| |
+---------------------------+--------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`remove_point<class_Gradient_method_remove_point>`\ (\ point\: :ref:`int<class_int>`\ ) |
+---------------------------+--------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`reverse<class_Gradient_method_reverse>`\ (\ ) |
+---------------------------+--------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Color<class_Color>` | :ref:`sample<class_Gradient_method_sample>`\ (\ offset\: :ref:`float<class_float>`\ ) |
+---------------------------+--------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`set_color<class_Gradient_method_set_color>`\ (\ point\: :ref:`int<class_int>`, color\: :ref:`Color<class_Color>`\ ) |
+---------------------------+--------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`set_offset<class_Gradient_method_set_offset>`\ (\ point\: :ref:`int<class_int>`, offset\: :ref:`float<class_float>`\ ) |
+---------------------------+--------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Enumerations
------------
.. _enum_Gradient_InterpolationMode:
.. rst-class:: classref-enumeration
enum **InterpolationMode**: :ref:`🔗<enum_Gradient_InterpolationMode>`
.. _class_Gradient_constant_GRADIENT_INTERPOLATE_LINEAR:
.. rst-class:: classref-enumeration-constant
:ref:`InterpolationMode<enum_Gradient_InterpolationMode>` **GRADIENT_INTERPOLATE_LINEAR** = ``0``
Linear interpolation.
.. _class_Gradient_constant_GRADIENT_INTERPOLATE_CONSTANT:
.. rst-class:: classref-enumeration-constant
:ref:`InterpolationMode<enum_Gradient_InterpolationMode>` **GRADIENT_INTERPOLATE_CONSTANT** = ``1``
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.
.. _class_Gradient_constant_GRADIENT_INTERPOLATE_CUBIC:
.. rst-class:: classref-enumeration-constant
:ref:`InterpolationMode<enum_Gradient_InterpolationMode>` **GRADIENT_INTERPOLATE_CUBIC** = ``2``
Cubic interpolation.
.. rst-class:: classref-item-separator
----
.. _enum_Gradient_ColorSpace:
.. rst-class:: classref-enumeration
enum **ColorSpace**: :ref:`🔗<enum_Gradient_ColorSpace>`
.. _class_Gradient_constant_GRADIENT_COLOR_SPACE_SRGB:
.. rst-class:: classref-enumeration-constant
:ref:`ColorSpace<enum_Gradient_ColorSpace>` **GRADIENT_COLOR_SPACE_SRGB** = ``0``
sRGB color space.
.. _class_Gradient_constant_GRADIENT_COLOR_SPACE_LINEAR_SRGB:
.. rst-class:: classref-enumeration-constant
:ref:`ColorSpace<enum_Gradient_ColorSpace>` **GRADIENT_COLOR_SPACE_LINEAR_SRGB** = ``1``
Linear sRGB color space.
.. _class_Gradient_constant_GRADIENT_COLOR_SPACE_OKLAB:
.. rst-class:: classref-enumeration-constant
:ref:`ColorSpace<enum_Gradient_ColorSpace>` **GRADIENT_COLOR_SPACE_OKLAB** = ``2``
`Oklab <https://bottosson.github.io/posts/oklab/>`__ color space. This color space provides a smooth and uniform-looking transition between colors.
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Property Descriptions
---------------------
.. _class_Gradient_property_colors:
.. rst-class:: classref-property
:ref:`PackedColorArray<class_PackedColorArray>` **colors** = ``PackedColorArray(0, 0, 0, 1, 1, 1, 1, 1)`` :ref:`🔗<class_Gradient_property_colors>`
.. rst-class:: classref-property-setget
- |void| **set_colors**\ (\ value\: :ref:`PackedColorArray<class_PackedColorArray>`\ )
- :ref:`PackedColorArray<class_PackedColorArray>` **get_colors**\ (\ )
Gradient's colors as a :ref:`PackedColorArray<class_PackedColorArray>`.
\ **Note:** Setting this property updates all colors at once. To update any color individually use :ref:`set_color()<class_Gradient_method_set_color>`.
**Note:** The returned array is *copied* and any changes to it will not update the original property value. See :ref:`PackedColorArray<class_PackedColorArray>` for more details.
.. rst-class:: classref-item-separator
----
.. _class_Gradient_property_interpolation_color_space:
.. rst-class:: classref-property
:ref:`ColorSpace<enum_Gradient_ColorSpace>` **interpolation_color_space** = ``0`` :ref:`🔗<class_Gradient_property_interpolation_color_space>`
.. rst-class:: classref-property-setget
- |void| **set_interpolation_color_space**\ (\ value\: :ref:`ColorSpace<enum_Gradient_ColorSpace>`\ )
- :ref:`ColorSpace<enum_Gradient_ColorSpace>` **get_interpolation_color_space**\ (\ )
The color space used to interpolate between points of the gradient. It does not affect the returned colors, which will always use nonlinear sRGB encoding.
\ **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>`.
.. rst-class:: classref-item-separator
----
.. _class_Gradient_property_interpolation_mode:
.. rst-class:: classref-property
:ref:`InterpolationMode<enum_Gradient_InterpolationMode>` **interpolation_mode** = ``0`` :ref:`🔗<class_Gradient_property_interpolation_mode>`
.. rst-class:: classref-property-setget
- |void| **set_interpolation_mode**\ (\ value\: :ref:`InterpolationMode<enum_Gradient_InterpolationMode>`\ )
- :ref:`InterpolationMode<enum_Gradient_InterpolationMode>` **get_interpolation_mode**\ (\ )
The algorithm used to interpolate between points of the gradient.
.. rst-class:: classref-item-separator
----
.. _class_Gradient_property_offsets:
.. rst-class:: classref-property
:ref:`PackedFloat32Array<class_PackedFloat32Array>` **offsets** = ``PackedFloat32Array(0, 1)`` :ref:`🔗<class_Gradient_property_offsets>`
.. rst-class:: classref-property-setget
- |void| **set_offsets**\ (\ value\: :ref:`PackedFloat32Array<class_PackedFloat32Array>`\ )
- :ref:`PackedFloat32Array<class_PackedFloat32Array>` **get_offsets**\ (\ )
Gradient's offsets as a :ref:`PackedFloat32Array<class_PackedFloat32Array>`.
\ **Note:** Setting this property updates all offsets at once. To update any offset individually use :ref:`set_offset()<class_Gradient_method_set_offset>`.
**Note:** The returned array is *copied* and any changes to it will not update the original property value. See :ref:`PackedFloat32Array<class_PackedFloat32Array>` for more details.
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Method Descriptions
-------------------
.. _class_Gradient_method_add_point:
.. rst-class:: classref-method
|void| **add_point**\ (\ offset\: :ref:`float<class_float>`, color\: :ref:`Color<class_Color>`\ ) :ref:`🔗<class_Gradient_method_add_point>`
Adds the specified color to the gradient, with the specified offset.
.. rst-class:: classref-item-separator
----
.. _class_Gradient_method_get_color:
.. rst-class:: classref-method
:ref:`Color<class_Color>` **get_color**\ (\ point\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Gradient_method_get_color>`
Returns the color of the gradient color at index ``point``.
.. rst-class:: classref-item-separator
----
.. _class_Gradient_method_get_offset:
.. rst-class:: classref-method
:ref:`float<class_float>` **get_offset**\ (\ point\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Gradient_method_get_offset>`
Returns the offset of the gradient color at index ``point``.
.. rst-class:: classref-item-separator
----
.. _class_Gradient_method_get_point_count:
.. rst-class:: classref-method
:ref:`int<class_int>` **get_point_count**\ (\ ) |const| :ref:`🔗<class_Gradient_method_get_point_count>`
Returns the number of colors in the gradient.
.. rst-class:: classref-item-separator
----
.. _class_Gradient_method_remove_point:
.. rst-class:: classref-method
|void| **remove_point**\ (\ point\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Gradient_method_remove_point>`
Removes the color at index ``point``.
.. rst-class:: classref-item-separator
----
.. _class_Gradient_method_reverse:
.. rst-class:: classref-method
|void| **reverse**\ (\ ) :ref:`🔗<class_Gradient_method_reverse>`
Reverses/mirrors the gradient.
\ **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>`.
.. rst-class:: classref-item-separator
----
.. _class_Gradient_method_sample:
.. rst-class:: classref-method
:ref:`Color<class_Color>` **sample**\ (\ offset\: :ref:`float<class_float>`\ ) :ref:`🔗<class_Gradient_method_sample>`
Returns the interpolated color specified by ``offset``. ``offset`` should be between ``0.0`` and ``1.0`` (inclusive). Using a value lower than ``0.0`` will return the same color as ``0.0``, and using a value higher than ``1.0`` will return the same color as ``1.0``. If your input value is not within this range, consider using :ref:`@GlobalScope.remap()<class_@GlobalScope_method_remap>` on the input value with output values set to ``0.0`` and ``1.0``.
.. rst-class:: classref-item-separator
----
.. _class_Gradient_method_set_color:
.. rst-class:: classref-method
|void| **set_color**\ (\ point\: :ref:`int<class_int>`, color\: :ref:`Color<class_Color>`\ ) :ref:`🔗<class_Gradient_method_set_color>`
Sets the color of the gradient color at index ``point``.
.. rst-class:: classref-item-separator
----
.. _class_Gradient_method_set_offset:
.. rst-class:: classref-method
|void| **set_offset**\ (\ point\: :ref:`int<class_int>`, offset\: :ref:`float<class_float>`\ ) :ref:`🔗<class_Gradient_method_set_offset>`
Sets the offset for the gradient color at index ``point``.
.. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
.. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
.. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
.. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
.. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
.. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
.. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
.. |void| replace:: :abbr:`void (No return value.)`