lib.py 872 B

12345678910111213141516171819202122232425262728
  1. from __future__ import print_function, absolute_import, division
  2. from rgbmatrix import RGBMatrix, RGBMatrixOptions
  3. from rgbmatrix import graphics
  4. def setup_matrix(**kwargs):
  5. o = RGBMatrixOptions()
  6. o.chain_length = 4
  7. for k, v in kwargs.iteritems():
  8. setattr(o, k, v)
  9. matrix = RGBMatrix(options=o)
  10. matrix.Clear()
  11. return matrix
  12. def scipy_demo():
  13. from PIL import Image
  14. import numpy as np
  15. from scipy.ndimage.interpolation import rotate
  16. from scipy.ndimage.filters import gaussian_filter
  17. draw = lambda pixels: matrix.SetImage(Image.fromarray(pixels.swapaxes(0, 1), 'RGB'))
  18. pixels = np.zeros(DIM, dtype=np.uint8)
  19. pixels[:, :, :] = (np.random.random(DIM) > 0.95) * 255
  20. for i in range(361):
  21. smooth = (180 - abs(i - 180)) / 80
  22. draw(gaussian_filter(rotate(pixels, i, order=0), [smooth, smooth, 0]))