Skip to main content

Easily generates a simple linear color array.

Project description

Color Vector

A simple utility that given two colors in RGB format and a number of desired intervals, returns an array of colors evenly distributed between (and including) the two starting colors.

Installation

pip install colorvector

How to use it

from colorvector import get_palette

palette = get_palette([0, 0, 0], [255, 255, 255], 3)
print(palette)
# [(0, 0, 0), (128, 128, 128), (255, 255, 255)]

Import the get_palette function and feed it your starting and ending colors as arrays of three integers (e.g. [0, 0, 0] and [255, 255, 255]) and an integer representing the number of colors you want in the palette (includes the two colors you gave it).

It will return an array of RGB values that fall on the vector between the starting and ending colors that are equidistant from each other (rounded to the nearest integer).

Input rules:

  • Colors must have exactly 3 integer values from 0 to 255.
  • n must be an integer greater than or equal to 2.

So, if you give it: [0, 0, 0], [255, 255, 255], 3 It will return: [(0, 0, 0), (128, 128, 128), (255, 255, 255)]

How the math works:

To lay out the points from Point 1 to Point 2,
Subtract (5,0,-1) - (1,2,3) to get the direction vector for the line.  In this case, <4, -2, -4>.

Then create the parametric equation for the line <x,y,z> = t * <4, -2, -4> + <1,2,3>

This set up leads to: 
when t = 0, <x,y,z> = 0* <4, -2, -4> + <1,2,3>  = < 1,2,3 >
when t = 1, <x,y,z> = 1* <4, -2, -4> + <1,2,3>  = < 5,0,-1 >

To distribute points evenly along this interval, distribute t evenly at the fractional size you need.  
For example for 6 points between and including both Point 1 and Point 2, divide into 5ths by letting 
t=0, .2, .4, .6, .8, 1.  ```

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

colorvector-0.0.2.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

colorvector-0.0.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file colorvector-0.0.2.tar.gz.

File metadata

  • Download URL: colorvector-0.0.2.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for colorvector-0.0.2.tar.gz
Algorithm Hash digest
SHA256 7305cc7f7a7995ea166bd1449af5321917483eef0bd94ff3fdc22c898f381c99
MD5 25e8829bb8dde24206bcbee4ffd0c9a1
BLAKE2b-256 7f536966aa8ad4db2a8c0ab502f30e5d3848cff05d01dc88dcd92aa76988979c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: colorvector-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for colorvector-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3219ee45d5c28d21b65555833c424bc386dd4439fa7e207d91c23149a3437f9d
MD5 a8376add78a55bd2a29c726982466ffa
BLAKE2b-256 e5b387fefddaaec7aee8a5fbbc5c7be354112e5e1aea9959613eba4f7bdd88e2

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