diff options
author | Jakob Stendahl <14180120+JakobST1n@users.noreply.github.com> | 2018-12-01 00:28:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-01 00:28:28 +0100 |
commit | 19df9946b438b38b9a4f3f57ad002981a1ae1eaf (patch) | |
tree | e8eb839a305502584e31e1b1a96c70406b9b6255 /src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Matrix.py | |
parent | fd7a1b51126f8b8f889807cb7d56bb3626a0e0b5 (diff) | |
parent | 7ec685de6e441af1f614bb9d18e25c047d21466b (diff) | |
download | Luxcena-Neo-19df9946b438b38b9a4f3f57ad002981a1ae1eaf.tar.gz Luxcena-Neo-19df9946b438b38b9a4f3f57ad002981a1ae1eaf.zip |
Merge pull request #6 from JakobST1n/dev
Written docs, finished CLI
Diffstat (limited to 'src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Matrix.py')
-rw-r--r-- | src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Matrix.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Matrix.py b/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Matrix.py new file mode 100644 index 0000000..0986b45 --- /dev/null +++ b/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Matrix.py @@ -0,0 +1,49 @@ +def getSegmentRange(segments, n): + """ Return a list of all the actual led-numbers in a segment """ + # Sum all the segments prior to the one we are looking for + i = 0 + start = 0 + while True: + if i >= n: break + start += segments[i] # Add number of leds in this segment to the start-index + i += 1 + + # Add all numbers in the segment we are looking for to a list + i = start + breakPoint = i + segments[n] + range = [] + while True: + range.append(i) + i += 1 + if i >= breakPoint: break + return range + + +class Matrix: + + def __init__(self, segments, matrix): + self.matrix = [] + for yPos in range(len(matrix)): + yVal = matrix[yPos] + + thisY = [] + for xPos in range(len(yVal)): + if matrix[yPos][xPos][1] == True: + thisY += reversed(getSegmentRange(segments, matrix[yPos][xPos][0])) + else: + thisY += getSegmentRange(segments, matrix[yPos][xPos][0]) + self.matrix.append(thisY) + + def get(self, x, y): + """ Return the value of a place in the matrix given x and y coordinates """ + return self.matrix[y][x] + +if __name__ == "__main__": + testMatrix = Matrix( + [2, 2, 2, 2, 2, 2, 2, 2, 2], + [ + [[0, False], [1, True], [2, False]], + [[3, True], [4, False], [5, True]], + [[6, False], [7, True], [8, False]] + ] + ) |