今天就写一个简单的文字闪烁效果,实现的效果比较简单,但也是值得学习的!
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
int main()
{
initgraph(600,400);//初始画布
setbkcolor(YELLOW);//背景颜色
cleardevice();//清屏
settextcolor(BLACK);//设置文字颜色
settextstyle(50,0,"华文行楷");//设置文字大小和字体
outtextxy(150,180,"文字闪烁效果!");//设置文字输出位置,文字内容
char text[4] = { 0 };
outtextxy(100,100,text);//整数输出
//循环实现闪烁效果
while (!_kbhit())//判断是否按键,等待输入按键为0,按键为1
{
settextcolor(RGB(255,255,255));
outtextxy(150, 180, "文字闪烁效果!");
outtextxy(100, 100, text);
Sleep(500);//休眠500ms
settextcolor(RGB(0, 0, 255));
outtextxy(150, 180, "文字闪烁效果!");
outtextxy(100, 100, text);
Sleep(500);
settextcolor(RGB(0, 255, 255));
outtextxy(150, 180, "文字闪烁效果!");
outtextxy(100, 100, text);
Sleep(500);
settextcolor(RGB(255, 0, 255));
outtextxy(150, 180, "文字闪烁效果!");
outtextxy(100, 100, text);
Sleep(500);
}
getchar();//等待输入,防止闪屏
closegraph();//关闭画布
return 0;
}