#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include
#include
using namespace std;
输出窗口背景颜色随机变化
void test01() {
initgraph(450, 400);
//setbkcolor(RGB(128, 0, 128)); //RGB配置颜色
//cleardevice();
srand((unsigned int)time(NULL));
//文字输出
//图形窗口只能显示字符串
settextstyle(10, 10, _T("黑体"));
outtextxy(100, 200, _T("dove"));
Sleep(3000);
while (1) {
setbkcolor(RGB(rand() % 256, rand() % 256, rand() % 256));
cleardevice();
Sleep(1500);
}
}
//把数字转为字符串
char str[10] = " ";
char *NumToChar(int num) {
sprintf(str, "秒表:%d", num);
return str;
}
void test02() {
initgraph(600, 450);
srand((unsigned int)time(NULL));
int i = 0;
while (!_kbhit()) //检查控制台窗口的按键是否被按下
{
setbkcolor(RGB(rand() % 256, rand() % 256, rand() % 256));
outtextxy(100, 240, "继续游戏");
outtextxy(0, 0, NumToChar(i));
i++;
Sleep(1000);
}
}
void test03() {
initgraph(600, 450);
setbkcolor(WHITE);
cleardevice();
setlinecolor(BLACK);
line(0, 0, 600, 450);
circle(300, 225, 100);
rectangle(200, 125, 400, 325);
setfillcolor(MAGENTA);
fillcircle(100, 100, 50);
}
void test04() {
initgraph(600, 450);
setbkcolor(WHITE);
setlinecolor(BLACK);
setfillcolor(MAGENTA);
int x = 100;
int y = 100;
while (1) {
cleardevice();
line(0, 0, 600, 450);
circle(300, 225, 100);
rectangle(200, 125, 400, 325);
fillcircle(x++, y++, 50);
Sleep(100);
}
}
加载图片
void test05() {
IMAGE img;
loadimage(&img, "algorithm.png");
int width = img.getwidth();
int height = img.getwidth();
initgraph(width, height);
putimage(0, 0, &img);
}
int main(){
//test01();
//test02();
//test03();
//test04();
test05();
getchar();
closegraph();
return 0;
}