Gradients

bouquet.gradients module provides various types of gradients.

Note

bouquet.gradients API is stable and won’t change dramatically.

How to use gradients with Vertex Instructions?

This is possible to use gradient textures with Vertex Instructions via the ***Gradient.render_texture() function. You can take a look at code examples in the Examples section.

class bouquet.gradients.ColorStop

Bases: EventDispatcher

The ColorStop class is used together with LinearGradient and RadialGradient. It defines a specific color at a certain position within the gradient.

color

The color to display at the stop position.

color is an ColorProperty and defaults to white.

position

The position of the color stop. The value should be in the range from 0.0 (start; one edge of gradient) to 1.0 (end; another edge of gradient). If the value exceeds the bounds, it will be set to:

  • 1.0 if the value is greater than 1.0;

  • 0.0 if the value is less than 0.0.

position is an BoundedNumericProperty and defaults to 0.0.

class bouquet.gradients.base.GradientBase(**kwargs)

Bases: AnchorLayout

Base class for linear and radial gradients. Do not use it directly; use a LinearGradient or a RadialGradient.

Hint

GradientBase is an AnchorLayout subclass, so you can put any widget inside it.

color_stops

List of ColorStop objects, describes how the gradient will look. If the list is empty, the gradient will be completely white.

Warning

bouquet gradients supports up to 1024 color stops.

Raises:

color_stops is a ListProperty and is empty by default.

class bouquet.gradients.LinearGradient(**kwargs)

Bases: GradientBase

The LinearGradient class provides a way to create linear gradients in Kivy.

A linear gradient is a visual effect where color is linearly interpolated between multiple color stops (ColorStop) across a straight line, known as the gradient line.

See also

Note, a linear gradient is rendered as described in the CSS specification.

angle

Defines the rotation of the gradient line in degrees. The angle determines the direction in which the gradient will be rendered, where 0 degrees represents a vertical gradient (from bottom to top), and 90 degrees represents a horizontal gradient (from left to right).

angle is an NumericProperty and defaults to 0.

static render_texture(**kwargs) Texture

Renders gradient at FBO and returns the texture.

Parameters:

kwargs – Any LinearGradient properties.

class bouquet.gradients.RadialGradient(**kwargs)

Bases: GradientBase

The RadialGradient class provides a way to create radial gradients in Kivy.

A radial gradient is a visual effect where color is linearly interpolated between multiple color stops (ColorStop) from the center to the border.

Hint

The value 0.0 of ColorStop.position represents the center, while 1.0 represents the border.

gradient_center_pos

Position of the gradient center.

gradient_center_pos is a ReferenceListProperty of (gradient_center_x, gradient_center_y) properties.

gradient_center_x

X-coordinate of the gradient’s center, where 0.0 corresponds to the left edge of the widget and 1.0 to the right edge.

gradient_center_x is an NumericProperty and defaults to 0.5.

gradient_center_y

Y-coordinate of the gradient’s center, where 0.0 corresponds to the top edge of the widget and 1.0 to the bottom edge.

gradient_center_y is an NumericProperty and defaults to 0.5.

radius

Radius of the gradient. A larger value extends the gradient effect, while a smaller value contracts it.

radius is an NumericProperty and defaults to 1.0.

static render_texture(**kwargs) Texture

Renders gradient at FBO and returns the texture.

Parameters:

kwargs – Any RadialGradient properties.

class bouquet.gradients.BilinearGradient(**kwargs)

Bases: AnchorLayout

Widget for creating a bilinear gradient background with customizable colors for each corner.

Hint

BilinearGradient is an AnchorLayout subclass, so you can put any widget inside it.

bottom_left_color

Color of the top bottom corner of gradient.

bottom_left_color is an ColorProperty and defaults to black.

bottom_right_color

Color of the bottom right corner of gradient.

bottom_right_color is an ColorProperty and defaults to red.

static render_texture(**kwargs) Texture

Renders gradient at FBO and returns the texture.

Parameters:

kwargs – Any BilinearGradient properties.

top_left_color

Color of the top left corner of gradient.

top_left_color is an ColorProperty and defaults to green.

top_right_color

Color of the top right corner of gradient.

top_right_color is an ColorProperty and defaults to yellow.

class bouquet.gradients.ConicalGradient(**kwargs)

Bases: GradientBase

The ConicalGradient class provides a way to create conical gradients in Kivy.

A conical gradient is a type of gradient in which colors smoothly blend around a central point, creating a cone-like appearance.

gradient_center_pos

Position of the gradient center.

gradient_center_pos is a ReferenceListProperty of (gradient_center_x, gradient_center_y) properties.

gradient_center_x

X-coordinate of the gradient’s center, where 0.0 corresponds to the left edge of the widget and 1.0 to the right edge.

gradient_center_x is an NumericProperty and defaults to 0.5.

gradient_center_y

Y-coordinate of the gradient’s center, where 0.0 corresponds to the top edge of the widget and 1.0 to the bottom edge.

gradient_center_y is an NumericProperty and defaults to 0.5.

static render_texture(**kwargs) Texture

Renders gradient at FBO and returns the texture.

Parameters:

kwargs – Any ConicalGradient properties.