Source code for gulik.palettes
# -*- coding: utf-8 -*-
[docs]def hue(base, count, distance=180):
"""
Creates a hue-rotation palette.
Parameters:
base (:class:`Color`): Color on which the palette will be based (i.e. the starting point of the hue-rotation).
count (int): number of colors the palette should hold.
distance (int or float): angular distance on a 360° hue circle thingamabob.
Returns:
list: A list of length **count** of :class:`Color` objects.
"""
if count == 1:
return [base]
palette = []
for i in range(0, count):
color = base.clone()
color.hue += i/(count - 1) * distance
palette.append(color)
return palette
[docs]def value(base, count, min=None, max=None):
"""
Creates a value-stepped palette
Parameters:
base (:class:`Color`): Color on which the palette will be based (i.e. source of hue and saturation)
count (int): number of colors the palette should hold
min (float >= 0 and <= 1): minimum value (the v in hsv)
max (float >= 0 and <= 1): maximum value
Returns:
list: A list of length **count** of :class:`Color` objects.
"""
if count == 1:
return [base]
if min is None:
if 0.2 > base.value:
min = base.value
else:
min = 0.2
if max is None:
if 0.6 < base.value:
max = base.value
else:
max = 0.6
span = max - min
step = span / (count - 1)
palette = []
for i in range(0, count):
color = base.clone()
color.value = max - i * step
palette.append(color)
return palette