Skip to main content

A simple module to handle colors

Project description

Verna

PyPI Build Status License: MIT

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.

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

  • a percentage in string form with a '%' at the end (eg: "20%")
  • an integer from 0 to 255 (eg: 0xff, 255)
  • a float from 0.0 to 1.0 (only for alpha property. eg: 0.4)

So, the following are valid:

color = Color(0x00ffff)
color.alpha = 0x80
color.alpha = "50%"
color.alpha = 0.5   # float values can be assigned
                    # only to alpha property

color.red = 0xff    # Same as color.red = 255
color.red = "100%"
color.green = 217
color.green = "85%"
color.blue = 0xf5
color.blue = "96%"

whereas the following will cause error:

color = Color(0x00ffff)
color.alpha = 0x1ff    # > 0xff
color.alpha = -1       # < 0.0
color.alpha = "120%"   # > 100%
color.alpha = "120"    # No '%' at end
color.alpha = 1.2      # > 1.0
color.alpha = True     # Invalid type: bool
color.red = 0.5        # float value accepted only for alpha

A Color object may be created in multiple ways.

By default, alpha value is 0.

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

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

verna-0.0.2.tar.gz (6.6 kB view hashes)

Uploaded Source

Built Distribution

verna-0.0.2-py3-none-any.whl (6.4 kB view hashes)

Uploaded Python 3

Supported by

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