#include <graphics.h>
#include <dos.h>
#define MaxWidth 640
#define MaxHeight 480
#define MiddX 320
#define MiddY 240
void main()
{
int gdriver=DETECT,gmode;
int x1,y1,x2,y2; /*确定矩形的4个参数*/
int stepX=4,stepY=3; /*画图间距*/
x1=x2=MiddX;
y1=y2=MiddY; /*初始化数据*/
initgraph(&gdriver,&gmode,"");
setwritemode(XOR_PUT); /*异或方式*/
setbkcolor(RED);
setcolor(YELLOW);
setlinestyle(SOLID_LINE,0,1);/*设置线形,实线,线宽1*/
while (!kbhit())
{
x1=x1-stepX;
y1=y1-stepY;
x2=x2+stepX;
y2=y2+stepY;
rectangle(x1,y1,x2,y2);
if (x2>=MaxWidth || x2==MiddX || y2>=MaxHeight || y2==MiddY){
stepY=-stepY;
stepX=-stepX;
}
delay(1000);
}
closegraph();
}
[此贴子已经被作者于2007-2-2 10:16:49编辑过]