Tools for Colour Pickers#

colour_tools package#

Tools for colourpickers

  • rgb, hsv and yiq colour systems

rgb2hash generate_gradient check draw_gradient draw_agradient vcheck vgenerate_gradient vdraw_gradient hash2rgb hsv_to_rgb hue_gradient circle polar2cart cart2polar rgb_to_hsv is_okay sb_okay rgb_to_yiq yiq_okay yiq_to_rgb

colour_tools.cart2polar(x, y, outer_w, inner_w)#
Conversion cartesian to polar coordinates

output hue, saturation of hsv; s adjusted

Parameters:
  • x (int) -- horiz coord

  • y (int) -- vert coord

  • outer_w (int) -- outside width of colour wheelimage

  • inner_w (int) -- inner width of colour wheelimage

Returns:

degc, sc -- degrees, length

Return type:

float

colour_tools.check(width, height, enlargement, square_size=4)#
Draw chequers in numpy as array

chequer value to grey or white depends on x position

Parameters:
  • width (int) -- canvas width

  • height (int) -- canvas height

  • enlargement (int) -- dpi enlargement factor

  • square_size (int) -- size each square

Returns:

array -- array of integers

Return type:

int

colour_tools.circle(canvas, x, y, radius, width=None, tags=None, outline=None, activeoutline=None)#

Returns Canvas circle using centre and radius

Parameters:
  • canvas (str) -- handle to canvas

  • x (int) -- x coord centre

  • y (int) -- y coord centre

  • radius (int) -- radius

  • width (int) -- outside ring

  • tags (str) -- tags

  • outline (str) -- colour outside ring

  • activeoutline (str) -- colour outside ring when mouse on ring

Return type:

canvas circle

colour_tools.draw_agradient(canvas, colour1, colour2, enlargement, width=300, height=26)#

Import alpha gradient into tkinter

Parameters:
  • canvas (str) -- parent widget

  • colour1 (tuple of int) -- start colour

  • colour2 (tuple of int) -- end colour

  • enlargement (int) -- dpi enlargement factor

  • steps (int) -- number steps in gradient

  • width (int) -- canvas width

  • height (int) -- canvas height

Return type:

None

colour_tools.draw_gradient(canvas, colour1, colour2, width=300, height=26)#

Import gradient into tkinter

Parameters:
  • canvas (str) -- parent widget

  • colour1 (tuple of int) -- start colour

  • colour2 (tuple of int) -- end colour

  • width (int) -- canvas width

  • height (int) -- canvas height

Return type:

None

colour_tools.generate_gradient(from_colour, to_colour, height, width)#

Draw gradient in numpy as array

Parameters:
  • from_colour (tuple of int) -- start colour

  • to_colour (tuple of int) -- end colour

  • height (int) -- canvas height

  • width (int) -- canvas width

Returns:

array -- array of integers

Return type:

int

colour_tools.hash2rgb(hash_)#

Conversion hash colour to rgb

Parameters:

hash (str) -- colour as hash

Returns:

rgb -- tuple of integers

Return type:

int

colour_tools.hsv_to_rgb(h, s, v)#
Conversion hsv to rgb

h 0-360, s & v 0-100

Parameters:
  • h (int) -- hue

  • s (int) -- saturation

  • v (int) -- value

Returns:

rgb -- tuple integers

Return type:

int

colour_tools.hue_gradient(canvas, width=300, height=26, steps=360)#

Returns hue gradient in tkinter canvas

Parameters:
  • canvas (str) -- parent widget

  • width (int) -- canvas width

  • height (int) -- canvas height

  • steps (int) -- steps

Returns:

image -- array of integers

Return type:

int

colour_tools.is_okay(index, text, input_)#
Validation for hash, which cannot be removed,

hex check on input after hash

Parameters:
  • index (str) -- index

  • text (str) -- text if accepted

  • input (str) -- current input

Returns:

various

Return type:

bool

colour_tools.polar2cart(phi, ray, outer_w, inner_w)#
Conversion polar to cartesian coordinates

original image 317x317 using inner 299x299 working area, ring can be on outer edge wheel, so allow a space around image image size used in calculating phi, ray from x,y phi,ray is h,s of hsv, ray adjusted

Parameters:
  • phi (float) -- angle

  • ray (float) -- distance to centre angle

  • outer_w (int) -- outside width of colour wheelimage

  • inner_w (int) -- inner width of colour wheelimage

Returns:

cartesian -- tuple of integers

Return type:

int

colour_tools.rgb2hash(red, green, blue)#

Convert rgb to hexadecimal

Parameters:
  • red (int) -- red component

  • green (int) -- green component

  • blue (int) -- blue component

Returns:

hash -- hexadecimal colour

Return type:

str

colour_tools.rgb_to_hsv(red, green, blue)#

convert rgb to hsv

Parameters:
  • red (int) -- red

  • green (int) -- Green

  • blue (int) -- blue

Returns:

hsv -- tuple of integers

Return type:

int

colour_tools.rgb_to_yiq(red, green, blue)#

Converts rgb to yiq

Parameters:
  • red (int) -- red

  • green (int) -- green

  • blue (int) -- blue

Returns:

yiq -- tuple of floats

Return type:

float

colour_tools.sb_okay(action, text, input_, lower, upper)#

Validation for colour components

Parameters:
  • action (str) -- insertion or deletion

  • text (str) -- text if accepted

  • input (str) -- current input

  • lower (str) -- lower limit

  • upper (int) -- upper limit

Returns:

various

Return type:

bool

colour_tools.vcheck(width, height, enlargement, alpha, square_size=4)#
Draw vertical chequers in numpy as array

chequer value to grey or white depends on y position

Parameters:
  • width (int) -- canvas width

  • height (int) -- canvas height

  • enlargement (int) -- dpi enlargement factor

  • alpha (int) -- opacity

  • square_size (int) -- size each square

Returns:

array -- array of integers

Return type:

int

colour_tools.vdraw_gradient(canvas, colour1, enlargement, alpha=255, width=30, height=30)#
Either fill in background

or import vertical gradient into tkinter

Parameters:
  • canvas (str) -- parent widget

  • colour1 (tuple of int) -- start colour

  • enlargement (int) -- dpi enlargement factor

  • alpha (int) -- opacity

  • width (int) -- canvas width

  • height (int) -- canvas height

Return type:

None

colour_tools.vgenerate_gradient(to_colour, alpha, height, width)#

Draw vertical gradient in numpy as array

Parameters:
  • to_colour (tuple of int) -- end colour

  • alpha (int) -- opacity

  • height (int) -- canvas height

  • width (int) -- canvas width

Returns:

array -- array of integers

Return type:

int

colour_tools.yiq_okay(action, text, input_, lower, upper)#

Validation for yiq colour components

Parameters:
  • action (str) -- action

  • text (str) -- text if accepted

  • input (str) -- current input

  • lower (str) -- lower and upper limits

  • upper (str) -- lower and upper limits

Returns:

various

Return type:

bool

colour_tools.yiq_to_rgb(y, i, q)#
Conversion yiq to rgb

incoming y 0 to 100, i, q ±100

Parameters:
  • y (str) -- luma

  • i (str) -- chrominance

  • q (str) -- chrominance

Returns:

rgb -- tuple of integers

Return type:

int