转:基于Turbo C2.0 的动画设计的例子

None.gif #include < graphics.h >
None.gif#include
< stdlib.h >
None.gif#include
< stdio.h >
None.gif#include
< conio.h >
None.gif
#define  IMAGE_SIZE 10 /* 宏定义*/
ExpandedBlockStart.gifContractedBlock.gif
void  draw_image( int  x,  int  y);  /**/ /* 画飞船函数的说明语句*/
ExpandedBlockStart.gifContractedBlock.gif
void  Putstar( void );  /**/ /* 画星星函数的说明语句*/
None.gifmain ()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
int graphdriver=DETECT; /**//* 检测适配器*/
ExpandedSubBlockStart.gifContractedSubBlock.gif    
int graphmode, color; /**//* 最高分辨率的值和色彩的值*/
ExpandedSubBlockStart.gifContractedSubBlock.gif    
void * pt_addr; /**//* 全局变量, 用于存储图像, 定义缓冲区空间*/
ExpandedSubBlockStart.gifContractedSubBlock.gif    
int x,y,maxx,maxy,midy,midx,i; /**//* 定义各变量数据类型*/
InBlock.gif    unsigned 
int size;
InBlock.gif    initgraph(
&graphdriver, &graphmode, "");
ExpandedSubBlockStart.gifContractedSubBlock.gif    maxx
=getmaxx(); /**//* 取得当前图形方式下允许的x 最大值*/
ExpandedSubBlockStart.gifContractedSubBlock.gif    maxy
=getmaxy(); /**//* 取得当前图形方式下允许的y 最大值*/
InBlock.gif    midx
=maxx/2;
ExpandedSubBlockStart.gifContractedSubBlock.gif    x
=0/**//* 定义x 的初始量为0*/
InBlock.gif    midy
=y=maxy/2;
ExpandedSubBlockStart.gifContractedSubBlock.gif    setcolor(YELLOW); 
/**//* 前景颜色设置为黄色*/
InBlock.gif    settextstyle(TRIPLEX_FONT, HORIZ_DIR, 
4);
InBlock.gif    settextjustify(CENTER_TEXT, CENTER_TEXT);
InBlock.gif    outtextxy(midx, 
400"AROUND THE WORLD");
ExpandedSubBlockStart.gifContractedSubBlock.gif    setbkcolor(BLACK); 
/**//* 背景颜色设置函数, 用法和setcolor相同*/
InBlock.gif    setcolor(RED);
InBlock.gif    setlinestyle(SOLID_LINE, 
0, THICK_WIDTH);
InBlock.gif    ellipse(midx, midy, 
1305016030);
InBlock.gif    setlinestyle(SOLID_LINE, 
0, NORM_WIDTH);
ExpandedSubBlockStart.gifContractedSubBlock.gif    draw_image(x, y); 
/**//* 画飞船*/
InBlock.gif    size
=imagesize (x, y- IMAGE_SIZE, x+(4*IMAGE_SIZE), y+
InBlock.gif        IMAGE_SIZE);
InBlock.gif    pt_addr
=malloc(size);
InBlock.gif    getimage (x, y 
- IMAGE_SIZE, x +(4*IMAGE_SIZE), y +IMAGE_SIZE, pt_addr);
ExpandedSubBlockStart.gifContractedSubBlock.gif    Putstar(); 
/**//* 画星*/
ExpandedSubBlockStart.gifContractedSubBlock.gif    setcolor(WHITE); 
/**//* 前景颜色为白色*/
InBlock.gif    setlinestyle(SOLID_LINE, 
0, NORM_WIDTH);
ExpandedSubBlockStart.gifContractedSubBlock.gif    rectangle(
00, maxx, maxy); /**//* 画矩形框*/
InBlock.gif    
while(! kbhit())
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        Putstar();
InBlock.gif        setcolor(RED);
InBlock.gif        setlinestyle(SOLID_LINE, 
0, THICK_WIDTH);
ExpandedSubBlockStart.gifContractedSubBlock.gif        ellipse(midx, midy, 
1305016030); /**//* 画一个围绕地球的
ExpandedSubBlockEnd.gif                                               光环
*/

InBlock.gif        setcolor(BLACK);
InBlock.gif        ellipse(midx, midy, 
1305016030);
InBlock.gif        
for(i=0; i<=13; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            setcolor(i
%2==0?LIGHTBLUE:BLACK); /**//*I 的值不同时选
ExpandedSubBlockEnd.gif                                              择的颜色也不同
*/

ExpandedSubBlockStart.gifContractedSubBlock.gif            ellipse(midx, midy, 
0360100100- 8*i); /**//* 画地球*/
InBlock.gif            setcolor(LIGHTBLUE);
InBlock.gif            ellipse(midx, midy, 
0360100- 8*i, 100);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        putimage (x, y
- IMAGE_SIZE, pt_addr, XOR_PUT); /**//* 恢复
ExpandedSubBlockEnd.gif                                                       原先的画面
*/

InBlock.gif        x
=x>=maxx?0:x+6;
ExpandedSubBlockStart.gifContractedSubBlock.gif        putimage(x, y
- IMAGE_SIZE, pt_addr, XOR_PUT); /**//* 在另
ExpandedSubBlockEnd.gif                                                      一位置显示飞船
*/

ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    free(pt_addr); 
/**//* 释放缓冲区空间*/
InBlock.gif    closegraph();
InBlock.gif    
return;
ExpandedBlockEnd.gif}

None.gif
void  draw_image( int  x,  int  y)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
int arw[11];
InBlock.gif    arw[
0]=x+10; arw[1]=y- 10; arw[2]=x+34; arw[3]=y- 6;
InBlock.gif    arw[
4]=x+34; arw[5]=y+6; arw[6]=x+10; arw[7]=y+10;
InBlock.gif    arw[
9]=x+10; arw[10]=y- 10;
InBlock.gif    moveto(x
+10, y- 4);
InBlock.gif    setcolor(
14);
InBlock.gif    setfillstyle(
14);
InBlock.gif    linerel(
- 3*10- 2*8);
InBlock.gif    moveto(x
+10, y+4);
InBlock.gif    linerel(
- 3*10+2*8);
InBlock.gif    moveto(x
+10, y);
InBlock.gif    linerel(
- 3*100);
InBlock.gif    setcolor(
3);
InBlock.gif    setfillstyle(
1, LIGHTBLUE);
InBlock.gif    fillpoly(
4, arw);
ExpandedBlockEnd.gif}

None.gif
void  Putstar( void )
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
int seed=1858;
InBlock.gif    
int i, dotx, doty, h, w, color, maxcolor;
InBlock.gif    maxcolor
=getmaxcolor();
InBlock.gif    w
=getmaxx();
InBlock.gif    h
=getmaxy();
InBlock.gif    srand(seed);
InBlock.gif    
for(i=0; i<250++i)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{dotx=i+random(w- 1);
InBlock.gif    doty
=i+random(h- 1);
InBlock.gif    color
=random(maxcolor);
InBlock.gif    setcolor(color);
InBlock.gif    putpixel(dotx, doty, color);
ExpandedSubBlockEnd.gif    circle(dotx
+1, doty+11); }

InBlock.gif    srand(seed);
ExpandedBlockEnd.gif}

以上代码转自:
基于Turbo C2.0 的动画设计
李国彪
( 嘉应学院电子信息工程系, 广东梅州514015)

转载于:https://www.cnblogs.com/FireYang/archive/2006/10/08/523177.html

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值