Skip to content

Commit 532b893

Browse files
authored
Add files via upload
1 parent 2f188a7 commit 532b893

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/format/render_bit_map.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const lowerPixelChar = '\u2584';
2+
const upperPixelChar = '\u2580';
3+
const fullBlockChar = '\u2588';
4+
5+
export function renderBitMap(
6+
bitMap: boolean[],
7+
width: number,
8+
height: number
9+
): string {
10+
let result = '';
11+
12+
for (let bitMapY = 0; bitMapY < height; bitMapY += 2) {
13+
for (let bitMapX = 0; bitMapX < width; bitMapX++) {
14+
const upperPixel = bitMap[bitMapY * width + bitMapX];
15+
const lowerPixel = (bitMapY + 1 < height) ? bitMap[(bitMapY + 1) * width + bitMapX] : false;
16+
17+
if (upperPixel && lowerPixel) {
18+
// Both pixels set
19+
result += '\x1b[37m' + fullBlockChar + '\x1b[0m';
20+
} else if (upperPixel && !lowerPixel) {
21+
// Upper pixel set
22+
result += '\x1b[37;48;5;16m' + upperPixelChar + '\x1b[0m';
23+
} else if (!upperPixel && lowerPixel) {
24+
// Lower pixel set
25+
result += '\x1b[37;48;5;16m' + lowerPixelChar + '\x1b[0m';
26+
} else {
27+
// No pixels set
28+
result += '\x1b[30m' + fullBlockChar + '\x1b[0m';
29+
}
30+
}
31+
result += '\n';
32+
}
33+
34+
return result;
35+
}

0 commit comments

Comments
 (0)