#include<graphics.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<dos.h>
#define IMAGE_s1 10
void draw_image(int x,int y);
void putstar(void);
void draw_earth();
void main()
{
int driver=DETECT;
int mode,color;
void *pt_addr;
void *buffer;
int x,y,maxy,maxx,midy,midx,i;
unsigned s1,s2;
initgraph(&driver,&mode,"C:\\BORLANDC\\BGI");
maxx=getmaxx(); /*取允许的最大x 值*/
maxy=getmaxy(); /*取允许的最大y 值*/
midx=maxx/2;
x=0;
midy=y=maxy/2;
setcolor(YELLOW);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);
settextjustify(CENTER_TEXT,CENTER_TEXT);
outtextxy(midx,400,"AROUND THE WORLD");
setbkcolor(BLACK);
setcolor(RED);
setlinestyle(SOLID_LINE,0,THICK_WIDTH);
ellipse(midx,midy,130,50,160,30);
setlinestyle(SOLID_LINE,0,NORM_WIDTH);
draw_image(x,y); /*画飞船*/
s1=imagesize(x,y-IMAGE_s1,x+(4*IMAGE_s1),y+IMAGE_s1);
pt_addr=malloc(s1);
getimage(x,y-IMAGE_s1,x+(4*IMAGE_s1),y+IMAGE_s1,pt_addr);
putstar();
setcolor(WHITE);
setlinestyle(SOLID_LINE,0,NORM_WIDTH);
rectangle(0,0,maxx,maxy); /*画方框*/
draw_earth();
s2=imagesize(midx-100,midy-100,midx+100,midy+100);
buffer=malloc(s2);
getimage(midx-100,midy-100,midx+100,midy+100,buffer);
while (!kbhit())
{
putstar();
setcolor(RED); /*画一个围绕地球的光环*/
setlinestyle(SOLID_LINE,0,THICK_WIDTH);
ellipse(midx,midy,130,50,160,30);
delay(1000);
setcolor(BLACK);
ellipse(midx,midy,130,50,160,30);
putimage(midx-100,midy-100,buffer,COPY_PUT);
putimage(x,y-IMAGE_s1,pt_addr,XOR_PUT);/*恢复原画面*/
x=x>=maxx?0:x+30;
putimage(x,y-IMAGE_s1,pt_addr,COPY_PUT);/*在另一个位置显示飞船*/
delay(1000);
putimage(midx-100,midy-100,buffer,XOR_PUT);
}
free(pt_addr);
closegraph();
}
void draw_image(int x,int y) /*画飞船*/
{
int arw[11];
arw[0]=x+10; arw[1]=y-10;
arw[2]=x+34; arw[3]=y-6;
arw[4]=x+34; arw[5]=y+6;
arw[6]=x+10; arw[7]=y+10;
arw[8]=x+10; arw[9]=y-10;
moveto(x+10,y-4);
setcolor(14);
setfillstyle(1,4);
linerel(-3*10,-2*8); /*画尾部天线*/
moveto(x+10,y+4);
linerel(-3*10,+2*8);
moveto(x+10,y);
linerel(-3*10,0);
setcolor(3);
setfillstyle(1,LIGHTBLUE);/*画本体*/
fillpoly(4,arw);
}
void putstar(void) /*画星星*/
{
int seed=1858;
int i,dotx,doty,h,w,color,maxcolor;
maxcolor=getmaxcolor(); /*得到当前模式和最多颜色数*/
w=getmaxx();
h=getmaxy();
srand(seed);
for(i=0;i<250;++i)
{
dotx=i+random(w-1);
doty=1+random(h-1);
color=random(maxcolor);
setcolor(color);
putpixel(dotx,doty,color);/*用点表示小星*/
circle(dotx+1,doty+1,1);/*用圆表示大星*/
}
srand(seed);
}
void draw_earth()
{
int i;
int midx=getmaxx()/2; /*取允许的最大x 值*/
int midy=getmaxy()/2; /*取允许的最大y 值*/
for (i=0;i<=12;i++) /*画地球*/
{
setcolor(LIGHTBLUE);
ellipse(midx,midy,0,360,100,100-8*i);
setcolor(LIGHTBLUE);
ellipse(midx,midy,0,360,100-8*i,100);
}
}
这是课本上的例题
但是不快
求助啊…………