aboutsummaryrefslogtreecommitdiff
path: root/README.rst
blob: 759e79689fc25976a9c174eaa989208d6ac8164e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
thcolor -- the touhey color management module
=============================================

This module is a color management module made by `Thomas Touhey`_ (``th``
is for ``touhey``) for the `textoutpc`_ project, a BBCode to HTML translation
module. It provides the following features:

- color management and conversions between formats (RGB, HSL, HWB, NCol, …).
- text-to-color using close-to-CSS format.

For more information, consult `the official website`_.

Examples
--------

Converting an RGB color to HSL:

.. code-block:: python

	from thcolor import Color

	color = Color(Color.Type.RGB, 55, 23, 224)
	print(color.hsl())

Converting a HSL color to RGB with an alpha value:

.. code-block:: python

	from thcolor import Color, Angle

	alpha = 0.75
	color = Color(Color.Type.HSL, Angle(Angle.Type.DEG, 180), 0.5, 1.0, alpha)
	print(color.rgba())

Converting a textual representation to the RGBA color components:

.. code-block:: python

	from thcolor import Color

	color = Color.from_text("darker(10%,  hsl(0, 1, 50.0%))")
	print(color.rgba())

Getting the CSS color representations (with compatibility for earlier CSS
versions) from a textual representation:

.. code-block:: python

	from thcolor import Color

	color = Color.from_text("gray(red( #123456 )/0.2/)")
	for repres in color.css():
		print(f"color: {repres}")

.. _Thomas Touhey: https://thomas.touhey.fr/
.. _textoutpc: https://textout.touhey.pro/
.. _the official website: https://thcolor.touhey.pro/