hbutils.color.utils¶
- Overview:
Useful color utilities based on color model
visual_distance¶
-
hbutils.color.utils.
visual_distance
(c1: hbutils.color.model.Color, c2: hbutils.color.model.Color) → float[source]¶ - Overview:
Get distance of 2 colors.
- Arguments:
c1 (
Color
): First color.c2 (
Color
): Second color.
- Returns:
distance (
float
): Distance of the colors.
- Examples::
>>> from hbutils.color import visual_distance, Color >>> visual_distance( ... Color.from_hex('#ff0000'), ... Color.from_hex('#00ff00') ... ) 2.5495097567963922 >>> visual_distance( ... Color.from_hex('#778800'), ... Color.from_hex('#887700') ... ) 0.16996731711975946
rnd_colors¶
-
hbutils.color.utils.
rnd_colors
(count, lightness=0.5, saturation=1.0, alpha=None, init_dis=4.0, lr=0.95, ur=1.5, rnd=None) → Iterator[hbutils.color.model.Color][source]¶ - Overview:
Generating random colors which are not similar.
- Parameters:
count – Count of colors.
lightness – Lightness of the colors (in HLS color space), default is
0.5
.saturation – Saturation of the colors (in HLS color space), default is
1.0
.alpha – Alpha of the colors, default is
None
.init_dis – Initial distance of colors, default is
4.0
.lr – Lower ratio when generating, default is
0.95
.ur – Upper ratio when generating, default is
1.5
.rnd – Random object to be used, default is
random.Random(0)
.
- Returns:
colors (
Iterator[Color]
): A iterator of colors.
- Examples::
>>> from hbutils.color import rnd_colors >>> for c in rnd_colors(12): ... print(c) #ff00ee #00ff00 #009cff #ff006c #c9ff00 #00f3ff #d100ff #ffaf00 #00ff6c #4100ff #ff5300 #46ff00
>>> for c in rnd_colors(12, 0.8, 0.9): ... print(c) #fa9ef4 #9efaa1 #9eb4fa #faa69e #c5fa9e #9ed6fa #f09efa #faf89e #9ef9fa #c09efa #fabe9e #9efaca