Skip to content
Permalink
Browse files
Simplify structure of colorization function
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Aug 29, 2016
1 parent fe3628e commit 1d0ce7e7e3407e6ee9c28e7226754f77b6b88041
Showing with 11 additions and 14 deletions.
  1. +11 −14 nikola/utils.py
@@ -1827,20 +1827,17 @@ def hash_str(string, pos):
def degreediff(dega, degb):
return min(abs(dega - degb), abs((degb - dega) + 360))

def husl_similar_from_base(string, base_color):
if husl is None:
req_missing(['husl'], 'Use color mixing (section colors)',
optional=True)
return base_color
h, s, l = husl.hex_to_husl(base_color)
old_h = h
idx = 0
while degreediff(old_h, h) < 27 and idx < 16:
h = 360.0 * (float(hash_str(string, idx)) / 255)
idx += 1
return husl.husl_to_hex(h, s, l)

return husl_similar_from_base(string, base_color)
if husl is None:
req_missing(['husl'], 'Use color mixing (section colors)',
optional=True)
return base_color
h, s, l = husl.hex_to_husl(base_color)
old_h = h
idx = 0
while degreediff(old_h, h) < 27 and idx < 16:
h = 360.0 * (float(hash_str(string, idx)) / 255)
idx += 1
return husl.husl_to_hex(h, s, l)


def color_hsl_adjust_hex(hexstr, adjust_h=None, adjust_s=None, adjust_l=None):

0 comments on commit 1d0ce7e

Please sign in to comment.