hzeller / flaschen-taschen

Noisebridge Flaschen Taschen display
GNU General Public License v3.0
196 stars 48 forks source link

Add an array interface to Flaschen. #65

Closed HexDecimal closed 2 years ago

HexDecimal commented 2 years ago

Allows Numpy to be used to read and write pixel data to the framebuffer. This is faster than setting self._data directly and allows all features of Numpy to be used while not adding a dependency on Numpy.

Example:

import flaschen
import numpy as np

ft = flaschen.Flaschen(UDP_IP, UDP_PORT, 45, 35)
pixels = np.asarray(ft)
pixels[1, :] = (255, 0, 0)  # Set 2nd row to red.
pixels[:, 1] = (0, 255, 0)  # Set 2nd column to green.
pixels[(pixels == (0, 0, 0)).all(axis=-1)] = (1, 1, 1)  # Change all (0, 0, 0) pixels to (1, 1, 1).
ft.send()