-
Notifications
You must be signed in to change notification settings - Fork 0
Matrix
This class will create a Matrix to controll the LEDs using two-dimensional cartesian coordiantes (x, y).
It will create two matrices, one with the adresses of the LEDs corresponding to their x and y coordinates, and one for the pixels of the matrix, so the user can see everything thats displayed on the LED matrix in the console.
Furthermore it will implement some functions to manipulate these matrices, such as inverting them and printog them to console.
You can also get the adress of a LED at given coordinates.
The constructor will create an array of adresses.
Arguments: X -> number of columns of the matrix, Y -> number of rows of the matrix, mode -> describes how the datalines of the LED Strips are arranged.
mode = 0:
datalines are arranged like a snake:
0 -> 1 -> 2 -> 3 -> 4
|
9 <- 8 <- 7 <- 6 <- 5
|
10 -> 11 -> 12 -> 13 -> 14
mode = 1:
datalines are arranged beginning each row at the same x-index:
0 -> 1 -> 2 -> 3 -> 4
|
<--------------------------
|
5 -> 6 -> 7 -> 8 -> 9
|
<--------------------------
|
10 -> 11 -> 12 -> 13 -> 14
mode is set to 0 by default
from lib import Matrix
X=8
Y=15
mat = Matrix(X, Y)
creates a Matrix-Object mat with a 8x15 mutidimensional adress-array and a snake-like Arrangement of the datalines.
from lib import Matrix
X=8
Y=15
mat = Matrix(X, Y, 1)
creates a Matrix-Object mat with a 8x15 mutidimensional adress-array and a row-like Arrangement of the datalines.
raises Exception ValueError: when X or Y value is smaler than 0 or mode is not 0 or 1.
Arguments: matrix -> two-dimensional array, that should be printed on the console.
Calling this method from the Matrix-object will return the given Matrix as a String.
Default is the pixel-Matrix.
If it returns the pixel Matrix it will only write the escaping strings for the colors each pixel has at his attribute, so that the returned String printed on the console will be colored.
returns A string, which is formatted, to display the matrix properly.
This method will initialize both the pixels- and the adresses-Arrays, it will be automatically called by the constructor.
Arguments: y -> y-value of the row that should be inverted.
Calling this method from the Matrix-object with the argument 0 <= y < Ymax will invert the corresponding row of the adresses-Matrix, it can be used to change the rows of the Matrix, so that they will correspond to your real datalines.
raises Exception: ValueError: when y is smaller than 0 or bigger than maximum Y of the matrix.
To invert the whole Matrix vertical, call invert_vertical from the Matrix-object.
Arguments: x -> x-value, y -> y-value
This Method returns the adress of the LED at the corresponding coordinates according to the adresses-Array.
The Arguments have to meet the following specs:
0 <= x < Xmax
0 <= y < Ymax
raises Exception: ValueError: when x or y are smaller tha 0 or bigger than maximum value in their specific direction in the matrix.
returns adress of the corresponding LED.
returns the pixel-matrix for the use in other classes.
Arguments: x -> x-value, y -> y-value, color -> rgb value.
This Method sets the pixel at (x, y) to the given color in the pixel-array.
raises Exception ValueError: when x or y are out of range (between 0 and Xmax or Ymax) or when one of the three color channels is out of range (between 0 and 256).