excolor.gradient
- excolor.gradient.show_gradient_sources(c, nx=160, ny=90, angle=0)[source]
Visualizes the positions of color sources on a background grid.
This function creates a plot showing where color sources would be placed for a given set of colors and image dimensions.
- Parameters:
c (list of str, str, or matplotlib.colors.Colormap) – Input colors or colormap. Can be: - A list of color strings - A color name (str) - A colormap name (str) - A Colormap instance
nx (int, default=160) – Number of pixels along horizontal axis
ny (int, default=90) – Number of pixels along vertical axis
angle (float, default=0) – Angle = 0 means that first color source is at the right edge of the image. The angle increases in math style (counter-clockwise).
- Returns:
Displays a matplotlib figure showing the color source positions
- Return type:
None
Examples
>>> show_gradient_sources(['#FF0000', '#00FF00', '#0000FF']) # Shows a plot with three color sources arranged in a circle
- excolor.gradient.fill_gradient(c, size=(1280, 720), angle=0, show=None, fname=None)[source]
Creates a gradient background image based on input colors or colormap.
This function generates a smooth gradient background using color sources arranged in a circular pattern. The gradient is created by interpolating between the color sources using inverse distance weighting.
- Parameters:
c (list of str, str, or matplotlib.colors.Colormap) – Input colors or colormap. Can be: - A list of color strings - A color name (str) - A colormap name (str) - A Colormap instance
size (tuple of int, default=(1280, 720)) – Size of the output image in pixels (width, height)
angle (float, default=0) – Angle = 0 means that first color source is at the right edge of the image. The angle increases in math style (counter-clockwise).
show (bool, optional) – Whether to display the generated image using matplotlib. If None, will show only if fname is None
fname (str, optional) – If provided, saves the image to the specified file path. Supported formats: .png, .jpg, .svg
- Returns:
The generated gradient background image in RGBA format
- Return type:
PIL.Image.Image
Notes
The function: 1. Processes input colors to get a suitable palette 2. Places color sources in a circular pattern 3. Creates a gradient by interpolating between sources 4. Optionally displays or saves the result
Examples
>>> img = background_gradient('viridis', size=(800, 600)) >>> img.show()