Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
card10
firmware
Merge requests
!19
Pycardium - add from_hsv / from_hsl to color.py [MANUAL MERGE]
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
Pycardium - add from_hsv / from_hsl to color.py [MANUAL MERGE]
wink/firmware:master
into
master
Overview
1
Commits
2
Pipelines
1
Changes
1
Closed
wink
requested to merge
wink/firmware:master
into
master
5 years ago
Overview
1
Commits
2
Pipelines
1
Changes
1
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
8e0943b2
2 commits,
5 years ago
1 file
+
69
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
pycardium/modules/py/color.py
+
69
−
0
Options
@@ -58,6 +58,75 @@ class Color(_ColorTuple):
blue
=
(
color
&
0x0000ff
)
return
cls
(
red
,
green
,
blue
)
@classmethod
def
from_hsv
(
cls
,
hue
,
saturation
,
value
):
"""
Create a color from a HSV tuple (hue, saturation, value).
This function is available both as a class method and directly inside
the color module:
**Example**:
.. code-block:: python
from color import Color
# Magenta
Color.from_hsv(300, 1, 1)
.. code-block:: python
import color
# Cyan
color.from_hsv(180, 1, 1)
Code via https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative
"""
def
f
(
n
):
k
=
(
n
+
(
hue
/
60
))
%
6
return
value
-
(
value
*
saturation
*
max
(
min
(
k
,
4
-
k
,
1
),
0
))
def
f2
(
x
):
return
round
(
f
(
x
)
*
255
)
return
cls
(
f2
(
5
),
f2
(
3
),
f2
(
1
))
@classmethod
def
from_hsl
(
cls
,
hue
,
saturation
,
lightness
):
"""
Create a color from a HSL tuple (hue, saturation, lightness).
This function is available both as a class method and directly inside
the color module:
**Example**:
.. code-block:: python
from color import Color
# Magenta
Color.from_hsl(300, 1, 0.5)
.. code-block:: python
import color
# Cyan
color.from_hsv(180, 1, 0.5)
Code via https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative
"""
a
=
saturation
*
min
(
lightness
,
1
-
lightness
)
def
f
(
n
):
k
=
(
n
+
hue
/
30
)
%
12
return
lightness
-
(
a
*
max
(
min
(
k
-
3
,
9
-
k
,
1
),
-
1
))
def
f2
(
x
):
return
round
(
f
(
x
)
*
255
)
return
cls
(
f2
(
0
),
f2
(
8
),
f2
(
4
))
def
__str__
(
self
):
# Return the color in hex
return
"
#{:02x}{:02x}{:02x}
"
.
format
(
Loading