Skip to main content

Python colour library

Project description

tp24

Build Status Documentation Status PyPI Version Github Version Python Versions License

GitHub code size in bytes GitHub repo size GitHub last commit GitHub Release Date Lines of code codecov CodeFactor

Python colour library, made by 7d

  • supports RGB, CMY, CMYK, HSV, HSL models & transparency
  • add & subtract colours to lighten & darken
  • find gradient of line with proportions
  • find similarity of colours
  • colour schemes: analogous, complementary, compound, triadic, tetradic
    • you can define more schemes too, given degree around wheel and number of colours
  • get hex of colour
  • get colour from hex or web name

Current version: v1.0

Documentation: https://tp24.readthedocs.io/en/latest/

Why 'tp24'?

tp24 stands for two power 24, or 2^24 which equals to 16777216, the number of colours that the RGB model can show.

Examples

Create a colour:

>>> col = tp24.rgb(255, 0, 0)
>>> col
rgb(255, 0, 0)

Convert colour from one model to another

>>> col = tp24.rgb(255, 0, 0)
>>> col.hsv()
hsv(0, 100, 100)
>>> col.cmyk()
cmyk(0, 100, 100, 0)

Get individual channels of colour

>>> col.r
255
>>> col.g
0
>>> col.b
0

Get hex value of colours

>>> col.hexv()
'#ff0000'
>>> col.hexv(compress=True)
'#f00'

Load colour from hex or web name

>>> tp24.rgb.from_hex("#987654")
rgb(152, 118, 84)
>>> tp24.hsv.from_web("orange")
hsv(39, 100, 100)

Lighten and darken colours by addition & subtraction

>>> col1 = tp24.rgb(255, 0, 0)
>>> col2 = tp24.hsl(270, 100, 50)
>>> col + col2
rgb(255, 0, 255)
>>> col - col2
rgb(127, 0, 0)

Mix colours

>>> col1*col2
rgb(192, 0, 128)
>>> tp24.tools.gradient(col1, col2)
rgb(192, 0, 128)
>>> tp24.tools.gradient(col1, col2, ap=0.25, bp=0.75)
rgb(160, 0, 191)

Find similarity of colours

>>> # works best in hsl/hsv
>>> col1 = tp24.hsl.from_web("red")
>>> col2 = tp24.hsl.from_web("orange")
>>> tp24.tools.similarity(col1, col2)
0.7388888888888889
>>> col2 = tp24.hsl.from_web("green")
>>> tp24.tools.similarity(col1, col2)
0.8055555555555557

Colour schemes

>>> col = tp24.rgb(255, 0, 0)
>>> col.analogous()
(rgb(255, 0, 128), rgb(255, 128, 0))
>>> col.compound()
(rgb(0, 255, 128), rgb(0, 128, 255))
>>> col.complementary()
rgb(0, 255, 255)
>>> col.triadic()
(rgb(0, 0, 255), rgb(0, 255, 0))
>>> col.tetradic()
(rgb(128, 0, 255), rgb(128, 255, 0), rgb(0, 255, 255))
>>> col.wheel(5, 72)
(rgb(204, 0, 255), rgb(204, 255, 0), rgb(0, 102, 255), rgb(0, 255, 102), rgb(0, 255, 102))

Invert values

>>> col.inverted()
rgb(0, 255, 255)

Support for transparency

>>> col
rgb(255, 0, 0
>>> col = col.add_alpha(50)
>>> col
rgba(255, 0, 0, 50)
>>> col = col.remove_alpha()
>>> col
rgb(255, 0, 0)

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

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

Source Distribution

tp24-1.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

tp24-1.0-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file tp24-1.0.tar.gz.

File metadata

  • Download URL: tp24-1.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.8.0 tqdm/4.60.0 CPython/3.8.9

File hashes

Hashes for tp24-1.0.tar.gz
Algorithm Hash digest
SHA256 a155fa1ed07023a49ed09714a58add8fb04d113793f7c3cdfebaea2c1e7f2329
MD5 54d7222c472b435e41c7b5d28045b89f
BLAKE2b-256 bbf266a8fd268f1d2cb85ff3cb8158e60fe42edc6b8baa88f08feae299dd40d9

See more details on using hashes here.

File details

Details for the file tp24-1.0-py3-none-any.whl.

File metadata

  • Download URL: tp24-1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.8.0 tqdm/4.60.0 CPython/3.8.9

File hashes

Hashes for tp24-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a7843b467643cd857d45e64bf132f77aa9f61f8337022be7894c822e1fee3b23
MD5 b080330a6f7ce50e0faf1b01b9f4b531
BLAKE2b-256 212b59c6bde7eca4659cd53779ff20553fb6d998498215d375ccef983ef08c64

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