Skip to main content

Easily create gradients under the form of a list with given-input colors

Project description

rgb-gradient

A Python package to create gradients.

Installation

pip install rgb-gradient

Usage

from rgb_gradient import get_linear_gradient

intermediate_colors = [(255, 0, 0), '#c86496', (160, 150, 80), '#14f0b4', '#0000ff'] # colors format rgb or hex

gradient = get_linear_gradient(colors=intermediate_colors, nb_colors=10, return_format='hex')

print(gradient)

Output:

['#ff0000', '#dc4161', '#c86496', '#b1816e', '#a09650', '#65bc7a', '#14f0b4', '#13e7b7', '#0a74db', '#0000ff']

Specification

Parameters Type/Format
colors A list containing:
 • tuples (3 int elements from 0 to 255)
or/and
 • string (representing the hexadecimal color value under the format '#rrggbb'
 e.g. red = '#ff0000').

Requirements: len(colors) <= nb_colors and len(colors) >= 2
nb_colors An int indicating how many colors will compose the gradient (including the colors already given).

Requirements: nb_colors >= 3 and nb_colors >= len(colors)
return_format A string to indicate in which format the colors composing the gradient are returned.
It can take the value 'rgb' (decimal format) or 'hex' (hexadecimal format).

Default value: 'rgb'
Requirements: return_format == 'rgb' or return_format == 'hex'

How it works

The RGB color model is composed of 3 values (red, green, blue) from 0 to 255. With that in mind, we can easily represent a color as a point on a 3D plan.
With the input of the previous example, it looks like that:

All input colors of the previous example placed as points on a 3D plan

The get_linear_gradient function first determine the global distance from the first point to the last one, passing through the other colors given (if any).

See on the image above, the global distance is all black lines added together.

With that distance, we can figure out how far from the starting point to place each missing point (simply place a point every global_distance/(nb_points_to_add+1)).

Here's the colors we got by calling the function get_linear_gradient with the arguments of the previous example:

All output colors of the previous example placed as points on a 3D plan

We can see a total of 10 colors, including 5 colors given and 5 new colors.

Tips

Ok, that doesn't look like a real gradient for now. Let's call get_linear_gradient again with a total of 1000 colors (nb_colors=1000).

1000 colors placed as points on a 3D plan, forming a real gradient

Yeah, this is better ;) Of course, the more you ask for colors, the better your gradient will be.

Support

If you need help or found a bug, consider opening an issue on the project.

License

The source code for this project is licensed under the GPLv3 license, which you can find in the LICENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rgb-gradient-0.0.2.tar.gz (41.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rgb_gradient-0.0.2-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

Details for the file rgb-gradient-0.0.2.tar.gz.

File metadata

  • Download URL: rgb-gradient-0.0.2.tar.gz
  • Upload date:
  • Size: 41.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for rgb-gradient-0.0.2.tar.gz
Algorithm Hash digest
SHA256 354123801d490dd949158ec307a6aea308335fc4783445c7cc5e6c6be8a6fa06
MD5 b508992b1fbb7958c46cde6a5ad4d913
BLAKE2b-256 43a3bc2c14f0bf95c2d508d4c58d2ad76fdeb9af7fc77c3bf985e0e0d8b27892

See more details on using hashes here.

File details

Details for the file rgb_gradient-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: rgb_gradient-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 28.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for rgb_gradient-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4ca92c36cc6a97d7b41e47ec5316c5aeb683648cb166ff8d7c3506c4dccc3b5d
MD5 dd99e2465f00d580e0eeaaefee39de06
BLAKE2b-256 4cbc78211bab5d25b3297e04f99159300feb44d6c14a984df3d0683e8170b9e7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page