moviepy.video.tools.drawing.color_gradient#
- moviepy.video.tools.drawing.color_gradient(size, p1, p2=None, vector=None, radius=None, color_1=0.0, color_2=1.0, shape='linear', offset=0)[source]#
Draw a linear, bilinear, or radial gradient.
The result is a picture of size
size, whose color varies gradually from color color_1 in positionp1to colorcolor_2in positionp2.If it is a RGB picture the result must be transformed into a 'uint8' array to be displayed normally:
- Parameters:
size (tuple or list) -- Size (width, height) in pixels of the final image array.
p1 (tuple or list) -- Position for the first coordinate of the gradient in pixels (x, y). The color 'before'
p1iscolor_1and it gradually changes in the direction ofp2until it iscolor_2when it reachesp2.p2 (tuple or list, optional) --
- Position for the second coordinate of the gradient in pixels (x, y).
Coordinates (x, y) of the limit point for
color_1andcolor_2.
vector (tuple or list, optional) -- A vector (x, y) in pixels that can be provided instead of
p2.p2is then defined as (p1 + vector).color_1 (tuple or list, optional) -- Starting color for the gradient. As default, black. Either floats between 0 and 1 (for gradients used in masks) or [R, G, B] arrays (for colored gradients).
color_2 (tuple or list, optional) -- Color for the second point in the gradient. As default, white. Either floats between 0 and 1 (for gradients used in masks) or [R, G, B] arrays (for colored gradients).
shape (str, optional) -- Shape of the gradient. Can be either
"linear","bilinear"or"circular". In a linear gradient the color varies in one direction, from pointp1to pointp2. In a bilinear gradient it also varies symmetrically fromp1in the other direction. In a circular gradient it goes fromcolor_1tocolor_2in all directions.radius (float, optional) -- If
shape="radial", the radius of the gradient is defined with the parameterradius, in pixels.offset (float, optional) -- Real number between 0 and 1 indicating the fraction of the vector at which the gradient actually starts. For instance if
offsetis 0.9 in a gradient going from p1 to p2, then the gradient will only occur near p2 (before that everything is of colorcolor_1) If the offset is 0.9 in a radial gradient, the gradient will occur in the region located between 90% and 100% of the radius, this creates a blurry disc of radiusd(p1, p2).
- Returns:
An Numpy array of dimensions (width, height, n_colors) of type float representing the image of the gradient.
- Return type:
image
Examples
color_gradient((10, 1), (0, 0), p2=(10, 0)) # from white to black #[[1. 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1]] # from red to green color_gradient( (10, 1), (0, 0), p2=(10, 0), color_1=(255, 0, 0), color_2=(0, 255, 0) ) # [[[ 0. 255. 0. ] # [ 25.5 229.5 0. ] # [ 51. 204. 0. ] # [ 76.5 178.5 0. ] # [102. 153. 0. ] # [127.5 127.5 0. ] # [153. 102. 0. ] # [178.5 76.5 0. ] # [204. 51. 0. ] # [229.5 25.5 0. ]]]