Skip to content

Commit

Permalink
Merge 4c6cd4e into 2b80488
Browse files Browse the repository at this point in the history
  • Loading branch information
Septolum committed Jan 15, 2020
2 parents 2b80488 + 4c6cd4e commit 8a66545
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 9 deletions.
27 changes: 18 additions & 9 deletions library/matrix11x7/__init__.py
Expand Up @@ -5,7 +5,11 @@
print("atexit not found. Matrix behaviour will be undefined on exit")
from . import is31fl3731
from .fonts import font5x7
import numpy
try:
import numpy
except ImportError:
from ._not_numpy import not_numpy
numpy = not_numpy()

__version__ = '0.0.1'

Expand Down Expand Up @@ -147,8 +151,8 @@ def grow_buffer(self, x, y):
:param y: Minimum y size
"""
x_pad = max(0, x - self.buf.shape[0])
y_pad = max(0, y - self.buf.shape[1])
x_pad = max(0, x - len(self.buf))
y_pad = max(0, y - len(self.buf[0]))
return numpy.pad(self.buf, ((0, x_pad), (0, y_pad)), 'constant')

def get_shape(self):
Expand Down Expand Up @@ -181,7 +185,8 @@ def show(self, before_display=None):
axis=axis)

# Chop a width * height window out of the display buffer
display_buffer = display_buffer[:display_width, :display_height]
#display_buffer = display_buffer[:display_width, :display_height]
display_buffer = [row[:display_height] for row in display_buffer[:display_width]]

# Allow the cropped buffer to be modified in-place before it's transformed and displayed
# This permits static elements to be drawn over the top of a scrolling buffer
Expand Down Expand Up @@ -448,16 +453,20 @@ def fill(self, brightness, x=0, y=0, width=None, height=None):
"""
if width is None:
width = self.buf.shape[0]
width = len(self.buf)

if height is None:
height = self.buf.shape[1]
height = len(self.buf[0])

if (x + width) > self.buf.shape[0] or (y + height) > self.buf.shape[1]:
if (x + width) > len(self.buf) or (y + height) > len(self.buf[0]):
self.buf = self.grow_buffer(x + width, y + height)

# Fill in one operation using a slice
self.buf[x:x + width, y:y + height] = brightness
#self.buf[x:x + width, y:y + height] = brightness
for i in range(x, x+width):
for j in range(y, y+height):
self.buf[i][j] = brightness
#[row[:display_height] for row in display_buffer[:display_width]]

def clear_rect(self, x, y, width, height):
"""Clear a rectangular area.
Expand Down Expand Up @@ -487,7 +496,7 @@ def get_buffer_shape(self):
Returns a tuple containing the width and height of the buffer.
"""
return self.buf.shape
return (len(self.buf), len(self.buf[0]))

def _pixel_addr(self, x, y):
"""Translate an x,y coordinate to a pixel index."""
Expand Down
73 changes: 73 additions & 0 deletions library/matrix11x7/_not_numpy.py
@@ -0,0 +1,73 @@
class not_numpy:
def pad(self, oldarray, padding, mode="constant"):
if mode != "constant":
raise NotImplementedError("No mode other than 'constant' has been implemented")
array = [[i for i in row] for row in oldarray]
x_pad = padding[0]
y_pad = padding[1]
x_pad_before = x_pad[0]
x_pad_after = x_pad[1]
y_pad_before = y_pad[0]
y_pad_after = y_pad[1]
if x_pad_before > 0:
for i in range(x_pad_before):
array.insert(0, [0] * len(array[0]))

if x_pad_after > 0:
for i in range(x_pad_after):
array.insert(len(array), [0] * len(array[0]))

if y_pad_before > 0:
for x in range(y_pad_before):
for i,j in enumerate(array):
array[i].insert(0, 0)

if y_pad_before > 0:
for x in range(y_pad_after):
for i,j in enumerate(array):
array[i].insert(len(j), 0)

return array

def roll(self, oldarray, shift, axis=0):
array = [[i for i in row] for row in oldarray]
if axis == 0:
if shift > 0:
for i in range(shift):
array.insert(0, array.pop(len(array) - 1))

if shift < 0:
for i in range(abs(shift)):
array.insert(len(array), array.pop(0))

if axis == 1:
if shift > 0:
for i in range(shift):
for j in array:
j.insert(0, j.pop(len(j) - 1))

if shift < 0:
for i in range(abs(shift)):
for j in array:
j.insert(len(j), j.pop(0))

return array

def flipud(self, oldarray):
array = [[i for i in row] for row in oldarray]
return array.reverse()

def fliplr(self, oldarray):
array = [[i for i in row] for row in oldarray]
for i in array:
i.reverse()
return array

def rot90(self, oldarray, rotations):
array = [[i for i in row] for row in oldarray]
for i in range(rotations):
array = list(reversed(list(zip(*array))))
return array

def zeros(self, shape):
return [[0]*shape[1] for i in range(shape[0])]

0 comments on commit 8a66545

Please sign in to comment.