5、运动的卫星
运动的卫星与QW43.C有些类似,只不过卫星是绕着屏幕不断地运行直到按任意键为止。
/*运动的卫星QW45.C*/
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#define SIZE 10
void draw_image(int x,int y);
void putpixel_demo(void);
int main()
{
int gmode,gdriver=DETECT,errorcode;
void *pt_addr;
int x,y,maxx,maxy,midx,midy,i;
unsigned int size;
initgraph(&gdriver,&gmode,"\\tc3\\bgi");
errorcode=graphresult();
if(errorcode!=0)
{
printf("Graphics error: %s\n",grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
maxx=getmaxx();
maxy=getmaxy();
midx=maxx/2;
x=0;
midy=maxy/2;
y=maxy/2;
setcolor(YELLOW);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);
settextjustify(CENTER_TEXT,CENTER_TEXT);
outtextxy(midx,400,"COMPUTER WORLD");
setcolor(BLACK);
setcolor(RED);
setlinestyle(SOLID_LINE,0,NORM_WIDTH);
setcolor(LIGHTBLUE);
for(i=0;i<13;i++)
{
ellipse(midx,midy,0,360,100,100-8*i);
ellipse(midx,midy,0,360,100-8*i,100);
}
draw_image(x,y);
size=imagesize(x,y-SIZE,x+(4*SIZE),y+SIZE);
pt_addr=malloc(size);
getimage(x,y-SIZE,x+(4*SIZE),y+SIZE,pt_addr);
putpixel_demo();
setcolor(WHITE);
setlinestyle(SOLID_LINE,0,NORM_WIDTH);
rectangle(0,0,maxx,maxy);
while(!kbhit())
{
putimage(x,y-SIZE,pt_addr,XOR_PUT);
x=x+5;
if(x>maxx)
x=0;
putimage(x,y-SIZE,pt_addr,XOR_PUT);
delay(100);
}
free(pt_addr);
closegraph();
return 0;
}
void draw_image(int x,int y)
{
moveto(x+10,y);
setcolor(14);
setfillstyle(1,4);
linerel(-3*10,2*10);
moveto(x+10,y);
linerel(-3*10,-2*10);
moveto(x+25,y);
linerel(-5*10,0);
fillellipse(x+13,y,8,8);
}
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |