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
Commits
07dab7e0
Verified
Commit
07dab7e0
authored
5 years ago
by
rahix
Browse files
Options
Downloads
Patches
Plain Diff
chore(pycardium): Fix Python-module code-style
Signed-off-by:
Rahix
<
rahix@rahix.de
>
parent
54e2fca8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#1564
passed
5 years ago
Stage: build
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pycardium/modules/py/color.py
+31
-29
31 additions, 29 deletions
pycardium/modules/py/color.py
pycardium/modules/py/display.py
+2
-0
2 additions, 0 deletions
pycardium/modules/py/display.py
pycardium/modules/py/htmlcolor.py
+2
-0
2 additions, 0 deletions
pycardium/modules/py/htmlcolor.py
with
35 additions
and
29 deletions
pycardium/modules/py/color.py
+
31
−
29
View file @
07dab7e0
...
...
@@ -53,9 +53,9 @@ class Color(_ColorTuple):
# Cyan
color.from_hex(0x00ffff)
"""
red
=
(
color
&
0x
ff
0000
)
>>
16
green
=
(
color
&
0x00
ff
00
)
>>
8
blue
=
(
color
&
0x0000
ff
)
red
=
(
color
&
0x
FF
0000
)
>>
16
green
=
(
color
&
0x00
FF
00
)
>>
8
blue
=
color
&
0x0000
FF
return
cls
(
red
,
green
,
blue
)
@classmethod
...
...
@@ -85,11 +85,14 @@ class Color(_ColorTuple):
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
))
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
...
...
@@ -120,20 +123,23 @@ class Color(_ColorTuple):
"""
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
))
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
__to_hsx
(
self
,
hsv
=
True
):
"""
Code via https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB
"""
xr
=
self
.
red
/
255
xr
=
self
.
red
/
255
xg
=
self
.
green
/
255
xb
=
self
.
blue
/
255
xb
=
self
.
blue
/
255
if
xr
==
xg
and
xr
==
xb
:
h
=
0
c_max
=
xr
...
...
@@ -164,7 +170,7 @@ class Color(_ColorTuple):
v
=
c_max
return
[
round
(
h
),
round
(
s
,
2
),
round
(
v
,
2
)]
else
:
l
=
(
(
c_max
+
c_min
)
/
2
)
l
=
(
c_max
+
c_min
)
/
2
if
x_max
==
0
:
s
=
0
elif
x_min
==
1
:
...
...
@@ -217,9 +223,9 @@ class Color(_ColorTuple):
if
sat
<
0
:
sat
=
0
rv
=
from_fn
(
hsx
[
0
],
sat
,
hsx
[
2
])
self
.
red
=
rv
.
red
self
.
red
=
rv
.
red
self
.
green
=
rv
.
green
self
.
blue
=
rv
.
blue
self
.
blue
=
rv
.
blue
def
__change_vlx
(
self
,
change
,
to_fn
,
from_fn
):
hsx
=
to_fn
()
...
...
@@ -229,9 +235,9 @@ class Color(_ColorTuple):
if
vlx
<
0
:
vlx
=
0
rv
=
from_fn
(
hsx
[
0
],
hsx
[
1
],
vlx
)
self
.
red
=
rv
.
red
self
.
red
=
rv
.
red
self
.
green
=
rv
.
green
self
.
blue
=
rv
.
blue
self
.
blue
=
rv
.
blue
def
change_hue
(
self
,
change
):
"""
...
...
@@ -257,9 +263,9 @@ class Color(_ColorTuple):
hue
=
hsx
[
0
]
+
change
hue
=
hue
%
360
rv
=
self
.
from_hsl
(
hue
,
hsx
[
1
],
hsx
[
2
])
self
.
red
=
rv
.
red
self
.
red
=
rv
.
red
self
.
green
=
rv
.
green
self
.
blue
=
rv
.
blue
self
.
blue
=
rv
.
blue
def
change_saturation_hsv
(
self
,
change
):
"""
...
...
@@ -418,9 +424,9 @@ class Color(_ColorTuple):
other
=
float
(
other
)
except
ValueError
:
return
NotImplemented
r
=
self
.
red
*
other
r
=
self
.
red
*
other
g
=
self
.
green
*
other
b
=
self
.
blue
*
other
b
=
self
.
blue
*
other
return
self
.
__get_bounded
(
round
(
r
),
round
(
g
),
round
(
b
))
def
__add__
(
self
,
other
):
...
...
@@ -447,9 +453,9 @@ class Color(_ColorTuple):
"""
if
not
isinstance
(
other
,
Color
):
return
NotImplemented
r
=
self
.
red
+
other
.
red
r
=
self
.
red
+
other
.
red
g
=
self
.
green
+
other
.
green
b
=
self
.
blue
+
other
.
blue
b
=
self
.
blue
+
other
.
blue
return
self
.
__get_bounded
(
r
,
g
,
b
)
def
__sub__
(
self
,
other
):
...
...
@@ -476,18 +482,17 @@ class Color(_ColorTuple):
"""
if
not
isinstance
(
other
,
Color
):
return
NotImplemented
r
=
self
.
red
-
other
.
red
r
=
self
.
red
-
other
.
red
g
=
self
.
green
-
other
.
green
b
=
self
.
blue
-
other
.
blue
b
=
self
.
blue
-
other
.
blue
return
self
.
__get_bounded
(
r
,
g
,
b
)
def
__str__
(
self
):
# Return the color in hex
return
"
#{:02x}{:02x}{:02x}
"
.
format
(
self
.
red
,
self
.
green
,
self
.
blue
)
return
"
#{:02x}{:02x}{:02x}
"
.
format
(
self
.
red
,
self
.
green
,
self
.
blue
)
# fmt: off
Color
.
BLACK
=
Color
.
from_hex
(
0x000000
)
Color
.
WHITE
=
Color
.
from_hex
(
0xffffff
)
Color
.
RED
=
Color
.
from_hex
(
0xff0000
)
...
...
@@ -496,6 +501,7 @@ Color.YELLOW = Color.from_hex(0xffff00)
Color
.
BLUE
=
Color
.
from_hex
(
0x0000ff
)
Color
.
MAGENTA
=
Color
.
from_hex
(
0xff00ff
)
Color
.
CYAN
=
Color
.
from_hex
(
0x00ffff
)
# fmt: on
# Add the colors and constructors to the module for convenience
...
...
@@ -506,9 +512,5 @@ Color.CYAN = Color.from_hex(0x00ffff)
# colors.BLACK
# colors.from_hex(0xc6c6c6)
globals
().
update
(
{
n
:
getattr
(
Color
,
n
)
for
n
in
dir
(
Color
)
if
n
.
startswith
(
"
from
"
)
or
n
.
isupper
()
}
{
n
:
getattr
(
Color
,
n
)
for
n
in
dir
(
Color
)
if
n
.
startswith
(
"
from
"
)
or
n
.
isupper
()}
)
This diff is collapsed.
Click to expand it.
pycardium/modules/py/display.py
+
2
−
0
View file @
07dab7e0
import
sys_display
import
color
class
Display
:
"""
The display class provides methods to allow the lcd display
...
...
@@ -145,5 +146,6 @@ class Display:
sys_display
.
circ
(
x
,
y
,
rad
,
col
,
filled
,
size
)
return
self
open
=
Display
.
open
close
=
Display
.
close
This diff is collapsed.
Click to expand it.
pycardium/modules/py/htmlcolor.py
+
2
−
0
View file @
07dab7e0
from
color
import
Color
# fmt: off
ALICEBLUE
=
Color
.
from_hex
(
0xf0f8ff
)
ANTIQUEWHITE
=
Color
.
from_hex
(
0xfaebd7
)
AQUA
=
Color
.
from_hex
(
0x00ffff
)
...
...
@@ -140,3 +141,4 @@ WHITE = Color.from_hex(0xffffff)
WHITESMOKE
=
Color
.
from_hex
(
0xf5f5f5
)
YELLOW
=
Color
.
from_hex
(
0xffff00
)
YELLOWGREEN
=
Color
.
from_hex
(
0x9acd32
)
# fmt: on
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment