C语言学习记录之——字符模式下轮流动画显示字符点阵

cxdzxc 2012-06-21 07:19:21
上键或+键显示下一字符,下键或-键显示上一字符,p键暂停,空格归0,esc退出
#include <stdio.h>
#include <time.h>
/*#include "asc_font.c"*/
#define draw '#'
#define x_origin 10
#define y_origin 5
#define word_byte 1*8
#define upkey 72
#define downkey 80
#define esckey 27
/*#define CLK_TCK CLOCKS_PER_SEC*/
char key,byte_dz;
int x=x_origin,word_origin=word_byte*0 /*(0x30+1)*/;
int byte_dz_i=0;

char word_sz[]=
{
/* 48 0x30 '0' */
0x38, /* 00111000 */
0x6c, /* 01101100 */
0xc6, /* 11000110 */
0xd6, /* 11010110 */
0xc6, /* 11000110 */
0x6c, /* 01101100 */
0x38, /* 00111000 */
0x00, /* 00000000 */

/* 49 0x31 '1' */
0x18, /* 00011000 */
0x38, /* 00111000 */
0x18, /* 00011000 */
0x18, /* 00011000 */
0x18, /* 00011000 */
0x18, /* 00011000 */
0x7e, /* 01111110 */
0x00, /* 00000000 */

/* 50 0x32 '2' */
0x7c, /* 01111100 */
0xc6, /* 11000110 */
0x06, /* 00000110 */
0x1c, /* 00011100 */
0x30, /* 00110000 */
0x66, /* 01100110 */
0xfe, /* 11111110 */
0x00, /* 00000000 */

/* 51 0x33 '3' */
0x7c, /* 01111100 */
0xc6, /* 11000110 */
0x06, /* 00000110 */
0x3c, /* 00111100 */
0x06, /* 00000110 */
0xc6, /* 11000110 */
0x7c, /* 01111100 */
0x00, /* 00000000 */

/* 52 0x34 '4' */
0x1c, /* 00011100 */
0x3c, /* 00111100 */
0x6c, /* 01101100 */
0xcc, /* 11001100 */
0xfe, /* 11111110 */
0x0c, /* 00001100 */
0x1e, /* 00011110 */
0x00, /* 00000000 */

/* 53 0x35 '5' */
0xfe, /* 11111110 */
0xc0, /* 11000000 */
0xc0, /* 11000000 */
0xfc, /* 11111100 */
0x06, /* 00000110 */
0xc6, /* 11000110 */
0x7c, /* 01111100 */
0x00, /* 00000000 */

/* 54 0x36 '6' */
0x38, /* 00111000 */
0x60, /* 01100000 */
0xc0, /* 11000000 */
0xfc, /* 11111100 */
0xc6, /* 11000110 */
0xc6, /* 11000110 */
0x7c, /* 01111100 */
0x00, /* 00000000 */

/* 55 0x37 '7' */
0xfe, /* 11111110 */
0xc6, /* 11000110 */
0x0c, /* 00001100 */
0x18, /* 00011000 */
0x30, /* 00110000 */
0x30, /* 00110000 */
0x30, /* 00110000 */
0x00, /* 00000000 */

/* 56 0x38 '8' */
0x7c, /* 01111100 */
0xc6, /* 11000110 */
0xc6, /* 11000110 */
0x7c, /* 01111100 */
0xc6, /* 11000110 */
0xc6, /* 11000110 */
0x7c, /* 01111100 */
0x00, /* 00000000 */

/* 57 0x39 '9' */
0x7c, /* 01111100 */
0xc6, /* 11000110 */
0xc6, /* 11000110 */
0x7e, /* 01111110 */
0x06, /* 00000110 */
0x0c, /* 00001100 */
0x78, /* 01111000 */
0x00, /* 00000000 */

/* 65 0x41 'A' */
0x38, /* 00111000 */
0x6c, /* 01101100 */
0xc6, /* 11000110 */
0xfe, /* 11111110 */
0xc6, /* 11000110 */
0xc6, /* 11000110 */
0xc6, /* 11000110 */
0x00, /* 00000000 */

/* 66 0x42 'B' */
0xfc, /* 11111100 */
0x66, /* 01100110 */
0x66, /* 01100110 */
0x7c, /* 01111100 */
0x66, /* 01100110 */
0x66, /* 01100110 */
0xfc, /* 11111100 */
0x00, /* 00000000 */

/* 67 0x43 'C' */
0x3c, /* 00111100 */
0x66, /* 01100110 */
0xc0, /* 11000000 */
0xc0, /* 11000000 */
0xc0, /* 11000000 */
0x66, /* 01100110 */
0x3c, /* 00111100 */
0x00, /* 00000000 */

/* 68 0x44 'D' */
0xf8, /* 11111000 */
0x6c, /* 01101100 */
0x66, /* 01100110 */
0x66, /* 01100110 */
0x66, /* 01100110 */
0x6c, /* 01101100 */
0xf8, /* 11111000 */
0x00, /* 00000000 */

/* 69 0x45 'E' */
0xfe, /* 11111110 */
0x62, /* 01100010 */
0x68, /* 01101000 */
0x78, /* 01111000 */
0x68, /* 01101000 */
0x62, /* 01100010 */
0xfe, /* 11111110 */
0x00, /* 00000000 */

/* 70 0x46 'F' */
0xfe, /* 11111110 */
0x62, /* 01100010 */
0x68, /* 01101000 */
0x78, /* 01111000 */
0x68, /* 01101000 */
0x60, /* 01100000 */
0xf0, /* 11110000 */
0x00 /* 00000000 */
};
...全文
144 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
W170532934 2012-06-21
  • 打赏
  • 举报
回复
拜读了。。
cxdzxc 2012-06-21
  • 打赏
  • 举报
回复
float mysleep(float delay)
{
float time_start, time_end;
time_start = clock();
time_end = clock();
if (delay < 0)
{
printf("value overflow\n");
delay = 0;
}
while ((time_end - time_start) / CLK_TCK < delay)
{
time_end = clock();
}
return delay;
}

void mygotoxy(int x,int y)
{
while(y--)
{printf("\n");}
while(x--)
{printf(" ");}
}

void hdz(char byte_dz)
{
int byte_bit_num=8;
while(byte_bit_num--)
{
if (byte_dz&0x80)
{
printf("%c",draw);
mysleep(0.01);
while (kbhit())
{
key = getch();
switch (key)
{
case upkey:
case '+':
word_origin=word_origin+word_byte;
if (word_origin>=word_byte*(0xf+1))
word_origin=0;
byte_dz_i=word_origin;
printf("\n");
return ;

case downkey:
case '-':
word_origin=word_origin-word_byte;
if (word_origin<0)
word_origin=word_byte*0xf;
byte_dz_i=word_origin;
printf("\n");
return ;

case esckey:
exit (0);
case ' ':
word_origin=0;
byte_dz_i=0;
break;
case 'p':
getch();
}
}
}
else
{
printf(" ");
}
byte_dz=byte_dz<<1;
}
}

int main(void)
{
system("cls");
mygotoxy(x_origin,y_origin);
while(1)
{
while(byte_dz_i<word_origin+word_byte)
{
byte_dz=word_sz[byte_dz_i++];
hdz(byte_dz);
printf("\n");
x=x_origin;
while(x--)
{printf(" ");}
}
mysleep(1); /*vc使用Sleep(x)*/

word_origin=byte_dz_i;
if (word_origin>=word_byte*(0xf+1))
word_origin=0;
if (word_origin<0)
word_origin=word_byte*0xf;
byte_dz_i=word_origin;
}
}

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧