File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments