diff --git a/1 - Code/hl3.py b/1 - Code/hl3.py index d89e5976d977738e4b4f5df73681614eb927ea30..8ce8d1da0243330ed86b4c2c5a89d29bb9119ff3 100644 --- a/1 - Code/hl3.py +++ b/1 - Code/hl3.py @@ -45,23 +45,50 @@ class color: def col(r, g, b): return (r, g, b) +def color_convert(color): + + # Handle hex an 0 + if isinstance(color, int): + if color == 0: + color = (0, 0, 0) + else: + color = ((color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF) + # Handle RGB tuple + elif isinstance(color, tuple) and len(color) == 3: + pass + # Error + else: + raise ValueError("Color must be an RGB tuple, a hex value, 0 or a valide color from the color class") + + return color + class matrix: + def clear(color): - # Handle hex an 0 - if isinstance(color, int): - if color == 0: - color = (0, 0, 0) - else: - color = ((color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF) - # Handle RGB tuple - elif isinstance(color, tuple) and len(color) == 3: - pass - # Error - else: - raise ValueError("Color must be an RGB tuple, a hex value, 0 or a valide color from the color class") + # Convert the color + color = color_convert(color) + # Set the full screen to the color for i in range(nb_line*nb_row): np[i] = color - - np.write() \ No newline at end of file + + # Apply the array + np.write() + + def set_line(line, color): + + # Check line + if line < 0 or line >= nb_line: + raise ValueError("Line is out of bound") + + # Convert the color + color = color_convert(color) + + # Set the line to the color + for i in range(line*nb_row, (line*nb_row)+nb_row): + np[i] = color + + # Apply the array + np.write() + diff --git a/1 - Code/main.py b/1 - Code/main.py index 57c50912f23a853d8c499c8e142bf2ad5597791e..9d0c6399cce4e6e5ab9e65257498402b7318a217 100644 --- a/1 - Code/main.py +++ b/1 - Code/main.py @@ -1,4 +1,4 @@ -from hl3 import color -from hl3 import matrix +from hl3 import * -matrix.clear(color.RED) +matrix.clear(0) +matrix.set_line(5, color.RED)