MCPcopy Create free account
hub / github.com/TheCSir/TerminalStart / updateColumn

Function updateColumn

src/utils/matrixUtils.ts:42–104  ·  view source on GitHub ↗
(
    column: MatrixColumn,
    rows: number,
    trailMultiplier: number,
    getChar: () => string
)

Source from the content-addressed store, hash-verified

40 * @param getChar Callback to generate a random character
41 */
42export function updateColumn(
43 column: MatrixColumn,
44 rows: number,
45 trailMultiplier: number,
46 getChar: () => string
47): void {
48 // Circular buffer shift: Move head back by 1 (wrapping around)
49 column.head = (column.head - 1 + rows) % rows;
50
51 // Reuse the cell object at the new head position (which represents logical row 0)
52 const newCell = column.cells[column.head];
53
54 // Determine content for the new cell
55 if (column.spaceRemaining > 0) {
56 newCell.val = ' ';
57 newCell.isHead = false;
58 column.spaceRemaining--;
59 } else {
60 if (column.lengthRemaining > 0) {
61 newCell.val = getChar();
62 newCell.isHead = false; // Will be determined in the loop below or implicitly?
63 // Actually, if it's a new char, it might be head?
64 // Wait, logic says:
65 // if (length > 0) matrix[0][j] = { val: getChar(), isHead: false };
66 // Then loop sets isHead based on below.
67 column.lengthRemaining--;
68 } else {
69 // End of trail, start new space
70 newCell.val = ' ';
71 newCell.isHead = false;
72 column.spaceRemaining = Math.floor(Math.random() * rows) + 1;
73 column.lengthRemaining = Math.floor((Math.random() * (rows - 3) + 3) * trailMultiplier);
74 }
75 }
76
77 // Mark heads and apply random glitch effect
78 // Iterate logical rows 0 to rows-1
79 for (let r = 0; r < rows; r++) {
80 const idx = (column.head + r) % rows;
81 const cell = column.cells[idx];
82
83 if (cell.val !== ' ') {
84 // Check below (logical r+1)
85 let isHead = false;
86 if (r + 1 < rows) {
87 const belowIdx = (column.head + r + 1) % rows;
88 const below = column.cells[belowIdx];
89 isHead = (below.val === ' ');
90 } else {
91 // Bottom of screen - treating below as space makes it head when it falls off?
92 // Original code: `const below = (r + 1 < rows) ? matrix[r + 1][j] : { val: ' ' };`
93 // So yes, if r == rows-1, below is space.
94 isHead = true;
95 }
96 cell.isHead = isHead;
97
98 // Glitch effect: 5% chance to change character if not head
99 if (!cell.isHead && Math.random() < 0.05) {

Callers 2

renderFunction · 0.90

Calls 1

getCharFunction · 0.50

Tested by

no test coverage detected