simetri.colors package

Submodules

simetri.colors.colors module

Color related operations

class simetri.colors.colors.Color(red: int = 0, green: int = 0, blue: int = 0, alpha: int = 1, space: ColorSpace = 'rgb')[source]

Bases: object

A class representing an RGB or RGBA color.

This class represents a color in RGB or RGBA color space. The default values for the components are normalized between 0.0 and 1.0. Values outside this range are automatically converted from the 0-255 range.

red

The red component of the color (0.0 to 1.0).

Type:

int

green

The green component of the color (0.0 to 1.0).

Type:

int

blue

The blue component of the color (0.0 to 1.0).

Type:

int

alpha

The alpha (transparency) component (0.0 to 1.0), default is 1.

Type:

int

space

The color space, default is “rgb”.

Type:

simetri.graphics.all_enums.ColorSpace

Examples

>>> red = Color(1.0, 0.0, 0.0)
>>> transparent_blue = Color(0.0, 0.0, 1.0, 0.5)
>>> rgb255 = Color(255, 0, 128)  # Will be automatically normalized
alpha: int = 1
blue: int = 0
copy()[source]
green: int = 0
property name
red: int = 0
property rgb
property rgb255
property rgba
property rgba255
space: ColorSpace = 'rgb'
class simetri.colors.colors.LinearGradient(x1: float = 0.0, y1: float = 0.0, x2: float = 0.0, y2: float = 0.0, colors: Sequence[Color] | None = None, positions: Sequence[Sequence[float]] | None = None, extend: bool = False)[source]

Bases: object

A class representing a linear gradient.

This class defines a linear gradient between two points with specified colors.

x1

The x-coordinate of the starting point.

Type:

float

y1

The y-coordinate of the starting point.

Type:

float

x2

The x-coordinate of the ending point.

Type:

float

y2

The y-coordinate of the ending point.

Type:

float

colors

A sequence of Color objects defining the gradient colors.

Type:

Sequence[simetri.colors.colors.Color]

positions

A sequence of Point objects defining the gradient positions.

Type:

Sequence[Sequence[float]]

extend

Whether to extend the gradient beyond its endpoints.

Type:

bool

Examples

>>> from simetri.graphics.common import Point
>>> gradient = LinearGradient(0, 0, 100, 100,
...                          [Color(1, 0, 0), Color(0, 0, 1)],
...                          [Point(0, 0), Point(100, 100)])
colors: Sequence[Color] = None
extend: bool = False
positions: Sequence[Sequence[float]] = None
x1: float = 0.0
x2: float = 0.0
y1: float = 0.0
y2: float = 0.0
class simetri.colors.colors.RadialGradient(x: float = 0.0, y: float = 0.0, radius: float = 0.0, colors: Sequence[Color] | None = None, positions: Sequence[Sequence[float]] | None = None, extend: bool = False)[source]

Bases: object

A class representing a radial gradient.

This class defines a radial gradient that radiates outward from a center point.

x

The x-coordinate of the center point.

Type:

float

y

The y-coordinate of the center point.

Type:

float

radius

The radius of the gradient.

Type:

float

colors

A sequence of Color objects defining the gradient colors.

Type:

Sequence[simetri.colors.colors.Color]

positions

A sequence of Point objects defining the gradient positions.

Type:

Sequence[Sequence[float]]

extend

Whether to extend the gradient beyond its defined radius.

Type:

bool

Examples

>>> from simetri.graphics.common import Point
>>> gradient = RadialGradient(50, 50, 30,
...                         [Color(1, 1, 1), Color(0, 0, 0)],
...                         [Point(50, 50), Point(80, 50)])
colors: Sequence[Color] = None
extend: bool = False
positions: Sequence[Sequence[float]] = None
radius: float = 0.0
x: float = 0.0
y: float = 0.0
simetri.colors.colors.blend(color1: Color, percent: int, color2: Color)[source]

percent% of color1 and (100-percent)% of color2 blended together to create a new color.

simetri.colors.colors.change_alpha(color, delta)[source]
simetri.colors.colors.change_blue(color, delta)[source]
simetri.colors.colors.change_green(color, delta)[source]
simetri.colors.colors.change_hue(color: Color, delta: float) Color[source]

Changes the hue of a color by a specified delta value.

Parameters:
  • color – The Color object to modify.

  • delta – The amount to adjust the hue value (between 0.0 and 1.0). Positive values increase hue, negative values decrease it.

Returns:

A new Color instance with the modified hue value.

simetri.colors.colors.change_lightness(color: Color, delta: float) Color[source]

Changes the lightness of a color by a specified delta value.

Parameters:
  • color – The Color object to modify.

  • delta – The amount to adjust the lightness value (between -1.0 and 1.0). Positive values increase lightness, negative values decrease it.

Returns:

A new Color instance with the modified lightness value.

simetri.colors.colors.change_red(color, delta)[source]
simetri.colors.colors.change_saturation(color: Color, delta: float) Color[source]

Changes the saturation of a color by a specified delta value.

Parameters:
  • color – The Color object to modify.

  • delta – The amount to adjust the saturation value (between -1.0 and 1.0). Positive values increase saturation, negative values decrease it.

Returns:

A new Color instance with the modified saturation value.

simetri.colors.colors.check_color(color)[source]
simetri.colors.colors.cmyk2rgb(c, m, y, k)[source]

Convert a CMYK color value to an RGB tuple.

simetri.colors.colors.get_color(value)[source]

if value is [r, g, b] return Color(r, g, b) if value is a string return Color(value) if value is a Color return value

simetri.colors.colors.hex2rgb(hex_val)[source]

Convert a hex color value to an RGB tuple.

simetri.colors.colors.hex_to_rgb(hexa)[source]

Convert hex to RGB.

simetri.colors.colors.hls2rgb(h, l, s)[source]
simetri.colors.colors.hsv2rgb(h, s, v)[source]
simetri.colors.colors.random() x in the interval [0, 1).
simetri.colors.colors.random_color()[source]

Return a random color.

simetri.colors.colors.rgb1to255(rgb)[source]
simetri.colors.colors.rgb255to1(rgb)[source]
simetri.colors.colors.rgb2hex(rgb)[source]

Convert an RGB tuple to a hex color value.

simetri.colors.colors.rgb2hls(r, g, b)[source]
simetri.colors.colors.rgb2hsv(r, g, b)[source]
simetri.colors.colors.rgb2yiq(r, g, b)[source]
simetri.colors.colors.rgb_to_hex(r, g, b)[source]

Convert RGB to hex.

simetri.colors.colors.yiq2rgb(y, i, q)[source]

simetri.colors.palettes module

class simetri.colors.palettes.PaletteType(value)

Bases: Enum

An enumeration.

DIVERGENT = 0
QUALITATIVE = 2
SEQUENTIAL = 1

simetri.colors.swatches module

Swatches from Japanese Color Harmony Dictionary by Teruko Sakurai

simetri.colors.swatches.random_swatch()[source]

Return a random swatch.

Module contents

simetri.colors.random() x in the interval [0, 1).