Implementing character patterns in C

I read this glyph implementation in Peter Van Der Linden's "Programming C Programmers ." He points this method to a glyph drawing. This question is strictly limited to the C programming context.

static unsigned short stopwatch[] = {
    0x07C6,
    0x1FF7,
    0x383B,
    0x600C,
    0x600C,
    0xC006,
    0xC006,
    0xDF06,
    0xC106,
    0xC106,
    0x610C,
    0x610C,
    0x3838,
    0x1FF0,
    0x07C0,
    0x0000
};

and then define

#define X )*2+1
#define _ )*2
#define s ((((((((((((((((0

for drawing glyphs with a width of 16 bits.

Then the above array is converted to a StopWatch glyph pattern.

How do we draw these glyphs on the screen without using graphics? Is there any method for drawing glyph patterns of other objects, such as a map outline, face of a person, roughly speaking, without the need to draw every pixel and not use normal C graphics?

Are there any algorithms that have been followed?

+3
source share
1 answer

:

int main()
{
    int i,j;
    for ( i=0;stopwatch[i];i++ )
    {
        for ( j=1<<16;j;j>>=1 ) printf("%c",stopwatch[i]&j?'o':' ');
        printf("\n");
    }
}

voila, :

      ooooo   oo 
    ooooooooo ooo
   ooo     ooo oo
  oo         oo  
  oo         oo  
 oo           oo 
 oo           oo 
 oo ooooo     oo 
 oo     o     oo 
 oo     o     oo 
  oo    o    oo  
  oo    o    oo  
   ooo     ooo   
    ooooooooo    
      ooooo      

define , :

$ gcc -E -x c -
#define X )*2+1
#define _ )*2
#define s ((((((((((((((((0 

s _ _ _ _ _ _ X X X X _ _ _ _ _ _

// will be preprocessed to:
^D

((((((((((((((((0 )*2 )*2 )*2 )*2 )*2 )*2 )*2+1 )*2+1 )*2+1 )*2+1 )*2 )*2 )*2 )*2 )*2 )*2

, ( 960 0x03c0), "".

+1

Source: https://habr.com/ru/post/1757197/


All Articles