diff --git a/Webserver/src/lib/client/matrix.ts b/Webserver/src/lib/client/matrix.ts index d328f6d..8ecaafc 100644 --- a/Webserver/src/lib/client/matrix.ts +++ b/Webserver/src/lib/client/matrix.ts @@ -26,14 +26,30 @@ export interface MatrixCell { color: string; } -// Create a 2D array containing MatrixCell objects with bg-color: black -export function initializeMatrix(scaling: number): MatrixCell[][] { - const fullWidth = +PUBLIC_LED_WIDTH * +PUBLIC_LED_CHAIN; - const fullHeight = +PUBLIC_LED_HEIGHT * +PUBLIC_LED_PARALLEL; +// Initialize matrix object based on environment variables +export function initializeMatrix(): Matrix { + const led_width = Number(PUBLIC_LED_WIDTH ?? '64'); + const led_height = Number(PUBLIC_LED_HEIGHT ?? '64'); - return Array.from({ length: fullHeight / scaling }, (_, y) => + const led_chain = Number(PUBLIC_LED_CHAIN ?? '1'); + const led_parallel = Number(PUBLIC_LED_PARALLEL ?? '1'); + + return { + width: led_width * led_parallel, + height: led_height * led_chain, + }; +} + +// Create a 2D array containing MatrixCell objects with bg-color: black +export function createGridArray(matrix: Matrix): MatrixCell[][] { + const { width, height, scale } = matrix; + + if (!scale) throw new Error('No scaling data provided!'); + const { factor } = scale; + + return Array.from({ length: height / factor }, (_, y) => Array.from( - { length: fullWidth / scaling }, + { length: width / factor }, (_, x) => ({ x, y, color: '000000' }) as MatrixCell ) ) as MatrixCell[][];