#include
<
graphics.h
>
#include
<
stdlib.h
>
#include
<
stdio.h
>
#include
<
conio.h
>
#define
IMAGE_SIZE 10 /* 宏定义*/
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
void
draw_image(
int
x,
int
y);
/**/
/* 画飞船函数的说明语句*/
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
void
Putstar(
void
);
/**/
/* 画星星函数的说明语句*/
main ()
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
int graphdriver=DETECT; /**//* 检测适配器*/
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
int graphmode, color; /**//* 最高分辨率的值和色彩的值*/
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
void * pt_addr; /**//* 全局变量, 用于存储图像, 定义缓冲区空间*/
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
int x,y,maxx,maxy,midy,midx,i; /**//* 定义各变量数据类型*/
unsigned int size;
initgraph(&graphdriver, &graphmode, "");
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
maxx=getmaxx(); /**//* 取得当前图形方式下允许的x 最大值*/
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
maxy=getmaxy(); /**//* 取得当前图形方式下允许的y 最大值*/
midx=maxx/2;
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
x=0; /**//* 定义x 的初始量为0*/
midy=y=maxy/2;
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
setcolor(YELLOW); /**//* 前景颜色设置为黄色*/
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4);
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(midx, 400, "AROUND THE WORLD");
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
setbkcolor(BLACK); /**//* 背景颜色设置函数, 用法和setcolor相同*/
setcolor(RED);
setlinestyle(SOLID_LINE, 0, THICK_WIDTH);
ellipse(midx, midy, 130, 50, 160, 30);
setlinestyle(SOLID_LINE, 0, NORM_WIDTH);
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
draw_image(x, y); /**//* 画飞船*/
size=imagesize (x, y- IMAGE_SIZE, x+(4*IMAGE_SIZE), y+
IMAGE_SIZE);
pt_addr=malloc(size);
getimage (x, y - IMAGE_SIZE, x +(4*IMAGE_SIZE), y +IMAGE_SIZE, pt_addr);
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Putstar(); /**//* 画星*/
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
setcolor(WHITE); /**//* 前景颜色为白色*/
setlinestyle(SOLID_LINE, 0, NORM_WIDTH);
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
rectangle(0, 0, maxx, maxy); /**//* 画矩形框*/
while(! kbhit())
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Putstar();
setcolor(RED);
setlinestyle(SOLID_LINE, 0, THICK_WIDTH);
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
ellipse(midx, midy, 130, 50, 160, 30); /**//* 画一个围绕地球的
光环*/
setcolor(BLACK);
ellipse(midx, midy, 130, 50, 160, 30);
for(i=0; i<=13; i++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
setcolor(i%2==0?LIGHTBLUE:BLACK); /**//*I 的值不同时选
择的颜色也不同*/
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
ellipse(midx, midy, 0, 360, 100, 100- 8*i); /**//* 画地球*/
setcolor(LIGHTBLUE);
ellipse(midx, midy, 0, 360, 100- 8*i, 100);
}
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
putimage (x, y- IMAGE_SIZE, pt_addr, XOR_PUT); /**//* 恢复
原先的画面*/
x=x>=maxx?0:x+6;
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
putimage(x, y- IMAGE_SIZE, pt_addr, XOR_PUT); /**//* 在另
一位置显示飞船*/
}
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
free(pt_addr); /**//* 释放缓冲区空间*/
closegraph();
return;
}
void
draw_image(
int
x,
int
y)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
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[9]=x+10; arw[10]=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
)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
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)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{dotx=i+random(w- 1);
doty=i+random(h- 1);
color=random(maxcolor);
setcolor(color);
putpixel(dotx, doty, color);
circle(dotx+1, doty+1, 1); }
srand(seed);
}
以上代码转自:
基于Turbo C2.0 的动画设计
李国彪
( 嘉应学院电子信息工程系, 广东梅州514015)