Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Chris
Pixelframe
Commits
d0157600
Commit
d0157600
authored
Dec 19, 2020
by
Christian Wander
Browse files
add limitations of size
parent
305b66ae
Changes
3
Hide whitespace changes
Inline
Side-by-side
blink.py
View file @
d0157600
...
...
@@ -6,7 +6,10 @@ BLUE = (0, 0, 255)
class
Thing
:
def
__init__
(
self
,
matrix
=
[],
file
=
None
,
width
=
12
,
height
=
12
):
def
__init__
(
self
,
matrix
=
[],
file
=
None
,
max_width
=
12
,
max_height
=
12
):
self
.
max_width
=
max_width
self
.
max_height
=
max_height
if
file
is
None
:
self
.
matrix
=
matrix
...
...
@@ -21,7 +24,8 @@ class Thing:
print
(
f
'>> loading image from
{
file
}
'
)
img
=
Image
.
open
(
file
)
w
,
h
=
img
.
size
w
,
h
=
self
.
_limit_dimensions
(
img
.
size
)
y
=
0
result
=
[]
...
...
@@ -40,6 +44,22 @@ class Thing:
self
.
matrix
=
result
def
_limit_dimensions
(
self
,
dim
):
"""
Accepts a tuple(width, height) and returns a new tuple(width, height)
where both values don't exceed this objects maximum dimensions
"""
w
,
h
=
dim
if
w
>
self
.
max_width
:
w
=
self
.
max_width
if
h
>
self
.
max_height
:
h
=
self
.
max_height
return
(
w
,
h
)
def
console_print
(
self
):
"""Prints the pixel matrix in this object to the console.
...
...
readme.md
0 → 100644
View file @
d0157600
run tests:
```
python3 -m unittest -v test
```
test.py
View file @
d0157600
...
...
@@ -36,6 +36,13 @@ class TestBlink(unittest.TestCase):
self
.
assertEqual
(
t
.
matrix
,
expected
)
def
test_limit_dimensions
(
self
):
t
=
blink
.
Thing
()
actual
=
t
.
_limit_dimensions
((
20
,
20
))
self
.
assertEqual
(
actual
,
(
12
,
12
))
if
__name__
==
"__main__"
:
unittest
.
main
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment