This release is a pre-release and may not be stable for production use.
Verna
A simple module to handle colors
Only RGBA colors are supported at the moment.
Installation
You need Python>=3.6 to use Verna.
It can be installed from PyPI with pip using
pip install verna
Usage
Colors are represented using objects of class Color.
The color value is essentially stored as an integer as the integer attribute.
Alpha channel value can be set to denote opacity level.
The following properties can be used to access the different color components.
color.alpha
color.red
color.green
color.blue
where color is an instance of Color.
The different color components can be edited with one of the following values
- an integer from 0 to 255 (eg: 0xff, 255)
- a float from 0.0 to 1.0 (eg: 0.4)
A value outside of valid range would cause exception.
So, the following are valid:
color = Color(0x00ffff)
color.alpha = 0x80
color.alpha = 0.5
color.red = 0xff # Same as color.red = 255
color.green = 217
color.blue = 0xf5
color.blue = 0.75
whereas the following will cause error:
color = Color(0x00ffff)
color.alpha = 0x1ff # > 0xff
color.alpha = -1 # < 0.0
color.alpha = 1.2 # > 1.0
color.alpha = True # Invalid type: bool
Color component value conversions
Following functions can be used for basic inter-conversion for the color component values:
> Color.to_int()
Example:
>>> color = Color.from_name("red") # 0xff0000
>>> red_int = Color.to_int(color.red) # 255
Convert a float in the range of 0.0 till 1.0 towards an int in the range of 0 to 255.
> Color.to_float()
Example:
>>> color = Color.from_name("darkolivegreen") # 0x556b2f
>>> red_float = Color.to_float(color.red) # 0.1843137254901961
Convert an int in the range of 0 till 255 towards a float in the range of 0 to 0.1
Conversion to percentage values can be done by multiplying the float
value obtained with Color.to_float() by 100.
>>> float_val = Color.to_float(54) # 0.21176470588235294
>>> percentage = float_val * 100 # 21.176470588235294
Creating `Color` object
A Color object may be created in multiple ways.
From integer color code
For example, cyan (solid), which has color code 0x00ffff can be created like
Color(0x00ffff)
which is same as
Color(65535)
From color name
Color.from_name() can be used to create Color objects from a CSS3 color name.
For example, cyan can be created with
Color.from_name('cyan')
From RGBA values
Color.from_rgba() can be used to create an instance of Color from RGBA values.
Color.from_rgba(255, 255, 0) # solid yellow
Color.from_rgba(255, 255, 0, 0.5) # translucent yellow
Other methods
Color.replace(red, green, blue, alpha)
Create a new Color object by replacing some of the component values
of a Color object.
Example:
>>> color = Color(0x8000ffff)
>>> color.replace(red=0x80, green=59, blue=0.5) # color with hex value 0x80803b80
Color.rgba()
Returns the color component values of red, green, blue, alpha as a tuple.
Example:
>>> color = Color(0x8000ffff)
>>> color.rgba()
(0, 255, 255, 0.5)
hex()
Return hexcode of the color value in ARGB format as a string.
Example:
>>> color = Color(0x8000ffff)
>>> hex(color)
0x8000ffff
int()
Return color of the color value in ARGB format as an integer.
Example:
>>> color = Color(0x8000ffff)
>>> int(color)
2147549183
Release files for verna 1.0.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| verna-1.0.0a1.tar.gz | 8.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| verna-1.0.0a1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.6 kB
Release files / verna-1.0.0a1.tar.gz
| Download URL | verna-1.0.0a1.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2b2e3ac504ff9018065aa6c57e0c74d59c589ce06d8141ca0771f04b456e852e
|
|
BLAKE2b-256 checksum How to use checksums |
bea73ef381c25cdd97a6cf6f1ecac09925c505f81fe88fe534ccb48afe70d314
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.9
|
Release files / verna-1.0.0a1-py3-none-any.whl
| Download URL | verna-1.0.0a1-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f65fd58df5bf43ed7bfcfe5a247465471b37502b01605fc53c3cc3733407eb93
|
|
BLAKE2b-256 checksum How to use checksums |
26a4ad608efbd256ff738469eb48d6a197d13ffbdcf8c6cbfe3cd0027bffb3e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.9
|