Commit d0157600 authored by Christian Wander's avatar Christian Wander
Browse files

add limitations of size

parent 305b66ae
...@@ -6,7 +6,10 @@ BLUE = (0, 0, 255) ...@@ -6,7 +6,10 @@ BLUE = (0, 0, 255)
class Thing: 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: if file is None:
self.matrix = matrix self.matrix = matrix
...@@ -21,7 +24,8 @@ class Thing: ...@@ -21,7 +24,8 @@ class Thing:
print(f'>> loading image from {file}') print(f'>> loading image from {file}')
img = Image.open(file) img = Image.open(file)
w, h = img.size
w, h = self._limit_dimensions(img.size)
y = 0 y = 0
result = [] result = []
...@@ -40,6 +44,22 @@ class Thing: ...@@ -40,6 +44,22 @@ class Thing:
self.matrix = result 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): def console_print(self):
"""Prints the pixel matrix in this object to the console. """Prints the pixel matrix in this object to the console.
......
run tests:
```
python3 -m unittest -v test
```
...@@ -36,6 +36,13 @@ class TestBlink(unittest.TestCase): ...@@ -36,6 +36,13 @@ class TestBlink(unittest.TestCase):
self.assertEqual(t.matrix, expected) 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__": if __name__ == "__main__":
unittest.main() unittest.main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment