Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed problem in range_to when hue should've cycled. #48

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions colour.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,18 +717,38 @@ def color_scale(begin_hsl, end_hsl, nb):
if nb < 0:
raise ValueError(
"Unsupported negative number of colors (nb=%r)." % nb)

step = tuple([float(end_hsl[i] - begin_hsl[i]) / nb for i in range(0, 3)]) \
if nb > 0 else (0, 0, 0)

def mul(step, value):
return tuple([v * value for v in step])

def add_v(step, step2):
return tuple([v + step2[i] for i, v in enumerate(step)])

return [add_v(begin_hsl, mul(step, r)) for r in range(0, nb + 1)]

end_h = end_hsl[0]
begin_h = begin_hsl[0]
end_s = end_hsl[1]
begin_s = begin_hsl[1]
end_l = end_hsl[2]
begin_l = begin_hsl[2]
# if distance through 1 is shorter than distance between, then we want to
# cycle through 1.0 instead of going all the way through all hues to get
# back to the color we want
if abs(end_h - begin_h) > abs((1.0 - begin_h) + end_h):
step_h = abs((1.0 - begin_h) + end_h) / nb
else:
if end_h != begin_h:
step_h = (end_h - begin_h) / nb
else:
step_h = 0.0
if end_l != begin_l:
step_l = (end_l - begin_l) / nb
else:
step_l = 0.0
if end_s != begin_s:
step_s = (end_s - begin_s) / nb
else:
step_s = 0.0
cs = [(begin_h, begin_s, begin_l)]
for i in range(1, nb):
new_h = cs[-1][0] + step_h
if new_h > 1.0:
new_h -= 1.0
cs.append((new_h, cs[-1][1] + step_s, cs[-1][2] + step_l))
cs.append(end_hsl)
return cs

##
## Color Pickers
Expand Down
14 changes: 7 additions & 7 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[metadata]
name = %%name%%
version = %%version%%
summary = %%description%%
name = colour
version = 0.1.5
summary = converts and manipulates various color representation (HSL, RVB, web, X11, ...)
description-file =
README.rst
CHANGELOG.rst
Expand All @@ -10,9 +10,9 @@ license_file = LICENSE
requires-dist =

## sdist info
author = %%author%%
author_email = %%email%%
home_page = http://github.com/vaab/%%name%%
author = Valentin LAB
author_email = [email protected]
home_page = http://github.com/vaab/colour
license = BSD 3-Clause License
classifier =
Programming Language :: Python
Expand All @@ -30,7 +30,7 @@ classifier =


[files]
modules = %%name%%
modules = colour
extra_files =
README.rst
CHANGELOG.rst
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
## Ensure that ``./autogen.sh`` is run prior to using ``setup.py``
##

if "%%short-version%%".startswith("%%"):
if "0.1.5".startswith("%%"):
import os.path
import sys
WIN32 = sys.platform == 'win32'
Expand Down