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
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
fpletz
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
No related tags found
No related merge requests found
Changes
3
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):
...
@@ -53,9 +53,9 @@ class Color(_ColorTuple):
# Cyan
# Cyan
color.from_hex(0x00ffff)
color.from_hex(0x00ffff)
"""
"""
red
=
(
color
&
0x
ff
0000
)
>>
16
red
=
(
color
&
0x
FF
0000
)
>>
16
green
=
(
color
&
0x00
ff
00
)
>>
8
green
=
(
color
&
0x00
FF
00
)
>>
8
blue
=
(
color
&
0x0000
ff
)
blue
=
color
&
0x0000
FF
return
cls
(
red
,
green
,
blue
)
return
cls
(
red
,
green
,
blue
)
@classmethod
@classmethod
...
@@ -85,11 +85,14 @@ class Color(_ColorTuple):
...
@@ -85,11 +85,14 @@ class Color(_ColorTuple):
Code via https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative
Code via https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative
"""
"""
def
f
(
n
):
def
f
(
n
):
k
=
(
n
+
(
hue
/
60
))
%
6
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
):
def
f2
(
x
):
return
round
(
f
(
x
)
*
255
)
return
round
(
f
(
x
)
*
255
)
return
cls
(
f2
(
5
),
f2
(
3
),
f2
(
1
))
return
cls
(
f2
(
5
),
f2
(
3
),
f2
(
1
))
@classmethod
@classmethod
...
@@ -120,20 +123,23 @@ class Color(_ColorTuple):
...
@@ -120,20 +123,23 @@ class Color(_ColorTuple):
"""
"""
a
=
saturation
*
min
(
lightness
,
1
-
lightness
)
a
=
saturation
*
min
(
lightness
,
1
-
lightness
)
def
f
(
n
):
def
f
(
n
):
k
=
(
n
+
hue
/
30
)
%
12
k
=
(
n
+
hue
/
30
)
%
12
return
lightness
-
(
a
*
max
(
min
(
k
-
3
,
9
-
k
,
1
),
-
1
))
return
lightness
-
(
a
*
max
(
min
(
k
-
3
,
9
-
k
,
1
),
-
1
))
def
f2
(
x
):
def
f2
(
x
):
return
round
(
f
(
x
)
*
255
)
return
round
(
f
(
x
)
*
255
)
return
cls
(
f2
(
0
),
f2
(
8
),
f2
(
4
))
return
cls
(
f2
(
0
),
f2
(
8
),
f2
(
4
))
def
__to_hsx
(
self
,
hsv
=
True
):
def
__to_hsx
(
self
,
hsv
=
True
):
"""
"""
Code via https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB
Code via https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB
"""
"""
xr
=
self
.
red
/
255
xr
=
self
.
red
/
255
xg
=
self
.
green
/
255
xg
=
self
.
green
/
255
xb
=
self
.
blue
/
255
xb
=
self
.
blue
/
255
if
xr
==
xg
and
xr
==
xb
:
if
xr
==
xg
and
xr
==
xb
:
h
=
0
h
=
0
c_max
=
xr
c_max
=
xr
...
@@ -164,7 +170,7 @@ class Color(_ColorTuple):
...
@@ -164,7 +170,7 @@ class Color(_ColorTuple):
v
=
c_max
v
=
c_max
return
[
round
(
h
),
round
(
s
,
2
),
round
(
v
,
2
)]
return
[
round
(
h
),
round
(
s
,
2
),
round
(
v
,
2
)]
else
:
else
:
l
=
(
(
c_max
+
c_min
)
/
2
)
l
=
(
c_max
+
c_min
)
/
2
if
x_max
==
0
:
if
x_max
==
0
:
s
=
0
s
=
0
elif
x_min
==
1
:
elif
x_min
==
1
:
...
@@ -217,9 +223,9 @@ class Color(_ColorTuple):
...
@@ -217,9 +223,9 @@ class Color(_ColorTuple):
if
sat
<
0
:
if
sat
<
0
:
sat
=
0
sat
=
0
rv
=
from_fn
(
hsx
[
0
],
sat
,
hsx
[
2
])
rv
=
from_fn
(
hsx
[
0
],
sat
,
hsx
[
2
])
self
.
red
=
rv
.
red
self
.
red
=
rv
.
red
self
.
green
=
rv
.
green
self
.
green
=
rv
.
green
self
.
blue
=
rv
.
blue
self
.
blue
=
rv
.
blue
def
__change_vlx
(
self
,
change
,
to_fn
,
from_fn
):
def
__change_vlx
(
self
,
change
,
to_fn
,
from_fn
):
hsx
=
to_fn
()
hsx
=
to_fn
()
...
@@ -229,9 +235,9 @@ class Color(_ColorTuple):
...
@@ -229,9 +235,9 @@ class Color(_ColorTuple):
if
vlx
<
0
:
if
vlx
<
0
:
vlx
=
0
vlx
=
0
rv
=
from_fn
(
hsx
[
0
],
hsx
[
1
],
vlx
)
rv
=
from_fn
(
hsx
[
0
],
hsx
[
1
],
vlx
)
self
.
red
=
rv
.
red
self
.
red
=
rv
.
red
self
.
green
=
rv
.
green
self
.
green
=
rv
.
green
self
.
blue
=
rv
.
blue
self
.
blue
=
rv
.
blue
def
change_hue
(
self
,
change
):
def
change_hue
(
self
,
change
):
"""
"""
...
@@ -257,9 +263,9 @@ class Color(_ColorTuple):
...
@@ -257,9 +263,9 @@ class Color(_ColorTuple):
hue
=
hsx
[
0
]
+
change
hue
=
hsx
[
0
]
+
change
hue
=
hue
%
360
hue
=
hue
%
360
rv
=
self
.
from_hsl
(
hue
,
hsx
[
1
],
hsx
[
2
])
rv
=
self
.
from_hsl
(
hue
,
hsx
[
1
],
hsx
[
2
])
self
.
red
=
rv
.
red
self
.
red
=
rv
.
red
self
.
green
=
rv
.
green
self
.
green
=
rv
.
green
self
.
blue
=
rv
.
blue
self
.
blue
=
rv
.
blue
def
change_saturation_hsv
(
self
,
change
):
def
change_saturation_hsv
(
self
,
change
):
"""
"""
...
@@ -418,9 +424,9 @@ class Color(_ColorTuple):
...
@@ -418,9 +424,9 @@ class Color(_ColorTuple):
other
=
float
(
other
)
other
=
float
(
other
)
except
ValueError
:
except
ValueError
:
return
NotImplemented
return
NotImplemented
r
=
self
.
red
*
other
r
=
self
.
red
*
other
g
=
self
.
green
*
other
g
=
self
.
green
*
other
b
=
self
.
blue
*
other
b
=
self
.
blue
*
other
return
self
.
__get_bounded
(
round
(
r
),
round
(
g
),
round
(
b
))
return
self
.
__get_bounded
(
round
(
r
),
round
(
g
),
round
(
b
))
def
__add__
(
self
,
other
):
def
__add__
(
self
,
other
):
...
@@ -447,9 +453,9 @@ class Color(_ColorTuple):
...
@@ -447,9 +453,9 @@ class Color(_ColorTuple):
"""
"""
if
not
isinstance
(
other
,
Color
):
if
not
isinstance
(
other
,
Color
):
return
NotImplemented
return
NotImplemented
r
=
self
.
red
+
other
.
red
r
=
self
.
red
+
other
.
red
g
=
self
.
green
+
other
.
green
g
=
self
.
green
+
other
.
green
b
=
self
.
blue
+
other
.
blue
b
=
self
.
blue
+
other
.
blue
return
self
.
__get_bounded
(
r
,
g
,
b
)
return
self
.
__get_bounded
(
r
,
g
,
b
)
def
__sub__
(
self
,
other
):
def
__sub__
(
self
,
other
):
...
@@ -476,18 +482,17 @@ class Color(_ColorTuple):
...
@@ -476,18 +482,17 @@ class Color(_ColorTuple):
"""
"""
if
not
isinstance
(
other
,
Color
):
if
not
isinstance
(
other
,
Color
):
return
NotImplemented
return
NotImplemented
r
=
self
.
red
-
other
.
red
r
=
self
.
red
-
other
.
red
g
=
self
.
green
-
other
.
green
g
=
self
.
green
-
other
.
green
b
=
self
.
blue
-
other
.
blue
b
=
self
.
blue
-
other
.
blue
return
self
.
__get_bounded
(
r
,
g
,
b
)
return
self
.
__get_bounded
(
r
,
g
,
b
)
def
__str__
(
self
):
def
__str__
(
self
):
# Return the color in hex
# Return the color in hex
return
"
#{:02x}{:02x}{:02x}
"
.
format
(
return
"
#{:02x}{:02x}{:02x}
"
.
format
(
self
.
red
,
self
.
green
,
self
.
blue
)
self
.
red
,
self
.
green
,
self
.
blue
)
# fmt: off
Color
.
BLACK
=
Color
.
from_hex
(
0x000000
)
Color
.
BLACK
=
Color
.
from_hex
(
0x000000
)
Color
.
WHITE
=
Color
.
from_hex
(
0xffffff
)
Color
.
WHITE
=
Color
.
from_hex
(
0xffffff
)
Color
.
RED
=
Color
.
from_hex
(
0xff0000
)
Color
.
RED
=
Color
.
from_hex
(
0xff0000
)
...
@@ -496,6 +501,7 @@ Color.YELLOW = Color.from_hex(0xffff00)
...
@@ -496,6 +501,7 @@ Color.YELLOW = Color.from_hex(0xffff00)
Color
.
BLUE
=
Color
.
from_hex
(
0x0000ff
)
Color
.
BLUE
=
Color
.
from_hex
(
0x0000ff
)
Color
.
MAGENTA
=
Color
.
from_hex
(
0xff00ff
)
Color
.
MAGENTA
=
Color
.
from_hex
(
0xff00ff
)
Color
.
CYAN
=
Color
.
from_hex
(
0x00ffff
)
Color
.
CYAN
=
Color
.
from_hex
(
0x00ffff
)
# fmt: on
# Add the colors and constructors to the module for convenience
# Add the colors and constructors to the module for convenience
...
@@ -506,9 +512,5 @@ Color.CYAN = Color.from_hex(0x00ffff)
...
@@ -506,9 +512,5 @@ Color.CYAN = Color.from_hex(0x00ffff)
# colors.BLACK
# colors.BLACK
# colors.from_hex(0xc6c6c6)
# colors.from_hex(0xc6c6c6)
globals
().
update
(
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
sys_display
import
color
import
color
class
Display
:
class
Display
:
"""
"""
The display class provides methods to allow the lcd display
The display class provides methods to allow the lcd display
...
@@ -145,5 +146,6 @@ class Display:
...
@@ -145,5 +146,6 @@ class Display:
sys_display
.
circ
(
x
,
y
,
rad
,
col
,
filled
,
size
)
sys_display
.
circ
(
x
,
y
,
rad
,
col
,
filled
,
size
)
return
self
return
self
open
=
Display
.
open
open
=
Display
.
open
close
=
Display
.
close
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
from
color
import
Color
# fmt: off
ALICEBLUE
=
Color
.
from_hex
(
0xf0f8ff
)
ALICEBLUE
=
Color
.
from_hex
(
0xf0f8ff
)
ANTIQUEWHITE
=
Color
.
from_hex
(
0xfaebd7
)
ANTIQUEWHITE
=
Color
.
from_hex
(
0xfaebd7
)
AQUA
=
Color
.
from_hex
(
0x00ffff
)
AQUA
=
Color
.
from_hex
(
0x00ffff
)
...
@@ -140,3 +141,4 @@ WHITE = Color.from_hex(0xffffff)
...
@@ -140,3 +141,4 @@ WHITE = Color.from_hex(0xffffff)
WHITESMOKE
=
Color
.
from_hex
(
0xf5f5f5
)
WHITESMOKE
=
Color
.
from_hex
(
0xf5f5f5
)
YELLOW
=
Color
.
from_hex
(
0xffff00
)
YELLOW
=
Color
.
from_hex
(
0xffff00
)
YELLOWGREEN
=
Color
.
from_hex
(
0x9acd32
)
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