mirror of
https://gitlab1.ptb.de/waltem01/Matrix
synced 2024-12-26 03:51:45 +00:00
commented matrix.ts file
This commit is contained in:
parent
d3016684f3
commit
a3e54d5f09
@ -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[][];
|
||||||
}
|
}
|
||||||
|
@ -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}
|
||||||
|
Loading…
Reference in New Issue
Block a user