commented matrix.ts file

This commit is contained in:
waltem01 2022-08-07 19:24:53 +02:00
parent d3016684f3
commit a3e54d5f09
2 changed files with 9 additions and 7 deletions

View File

@ -1,14 +1,16 @@
// Interface to represent a singualr matrix cell object
export interface MatrixCell { export interface MatrixCell {
xIndex: number; x: number;
yIndex: number; y: number;
color: string; color: string;
} }
// Create a 2D array containing MatrixCell objects with bg-color: black
export function initializeMatrix(scaling: number): MatrixCell[][] { export function initializeMatrix(scaling: number): MatrixCell[][] {
return Array.from({ length: 192 / scaling }, (_, yIndex) => return Array.from({ length: 192 / scaling }, (_, y) =>
Array.from( Array.from(
{ length: 192 / scaling }, { length: 192 / scaling },
(_, xIndex) => ({ xIndex, yIndex, color: '000000' }) as MatrixCell (_, x) => ({ x, y, color: '000000' }) as MatrixCell
) )
) as MatrixCell[][]; ) as MatrixCell[][];
} }

View File

@ -579,12 +579,12 @@
on:mouseup|preventDefault={() => (mousePressed = false)} on:mouseup|preventDefault={() => (mousePressed = false)}
> >
{#each matrix as row} {#each matrix as row}
<tr data-y={row[0].yIndex}> <tr data-y={row[0].y}>
{#each row as cell} {#each row as cell}
<td <td
data-x={cell.xIndex} data-x={cell.x}
style="padding: {padding}rem; background-color: #{getContrastColor(cell.color)}" style="padding: {padding}rem; background-color: #{getContrastColor(cell.color)}"
class="{gamepad && gameCoords.x === cell.xIndex && gameCoords.y === cell.yIndex class="{gamepad && gameCoords.x === cell.x && gameCoords.y === cell.y
? 'opacity-50' ? 'opacity-50'
: 'opacity-0'} hover:opacity-50" : 'opacity-0'} hover:opacity-50"
on:mousemove={setMousePixel} on:mousemove={setMousePixel}