⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 精细绘图及动画.htm

📁 精细绘图及动画的程序
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0044)http://myweb.yzu.edu.cn/toby88/c/c1/jcht.htm -->
<!-- saved from url=(0045)http://beckenglish.51.net/cbook/arti/plan.htm --><HTML><HEAD><TITLE>精细绘图及动画</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2800.1106" name=GENERATOR><LINK 
href="../%BE%AB%CF%B8%BB%E6%CD%BC%BC%B0%B6%AF%BB%AD.files/moy.css" type=text/css 
rel=stylesheet></HEAD>
<BODY onload="">
<P align=center><STRONG class=orang_text>精细绘图及动画</STRONG></P>
<P>制个程序是本人自己编写,所以这里能后做出详细解释。程序运行后会在屏幕上用triplex_font显示“press any key for set 
off”,下方是用基本的线条画出的发射架(有点粗糙),即程序中的DrawGun()函数,当按下任意键后,将在发射架上方出现一个用横线填充的飞机,同时背景被繁星填充,此时必须按住任意键不放,否则飞机将不会发射。发射完成后,即飞机坐标小于0,将出现一句话:"successfully!!!,press 
ESC to quit",若中途按ESC退出,则飞机Y坐标不小于0,将出现"failue,..."这句话。</P>
<P>#include&lt;graphics.h&gt;<BR>#include&lt;conio.h&gt;<BR>#include&lt;stdio.h&gt;<BR>#include&lt;stdlib.h&gt;<BR>#include&lt;alloc.h&gt;<BR><BR>#define 
ESC&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
0x1b/*ESC的ASCII码,十六进制*/<BR><BR>void InstallGraph(void);/*图形程序加载函数的说名语句*/<BR>void 
DrawGun(void);&nbsp;&nbsp;&nbsp;&nbsp; /*画发射架函数的说明语句*/<BR>void 
DrawPlan(void);&nbsp;&nbsp; /*画飞机函数的说明语句*/<BR>void DrawStar(void);&nbsp; 
/*画星函数的说明语句*/<BR><BR>void *buf;&nbsp;&nbsp; /*全局变量,用于存储飞机的图像*/<BR>int x0=300; 
/*以下是飞机的位置初始化参数*/<BR>int y0=340;<BR>int width1=5;<BR>int width2=20;<BR>int 
height=25;<BR>int y1=8;<BR>int y2=15;<BR>int y3=23;<BR>int 
y4=38;<BR><BR>/*主函数开始*/<BR>main()<BR>{<BR>&nbsp;&nbsp;&nbsp; int 
size;<BR>&nbsp;&nbsp;&nbsp; int i=0;<BR>&nbsp;&nbsp;&nbsp; int 
key;<BR>&nbsp;&nbsp;&nbsp; int station;<BR><BR><BR>&nbsp;&nbsp;&nbsp; 
InstallGraph();<BR>&nbsp;&nbsp;&nbsp; setbkcolor(BLACK);<BR>&nbsp;&nbsp;&nbsp; 
cleardevice();/*图形驱动程序和屏幕初始化工作完成*/<BR><BR>&nbsp;&nbsp;&nbsp; 
setcolor(BLUE);/*设置字的颜色*/<BR>&nbsp;&nbsp;&nbsp; 
settextstyle(TRIPLEX_FONT,0,4);/*设置字体*/<BR>&nbsp;&nbsp;&nbsp; 
outtextxy(80,100,"Ready!...Any key to SET OFF !!!");<BR>&nbsp;&nbsp;&nbsp; 
DrawGun();&nbsp; /*画出发射架*/<BR>&nbsp;&nbsp;&nbsp; getch(); /*if press key,clear 
the words and start*/<BR><BR>&nbsp;&nbsp;&nbsp; 
cleardevice();<BR>&nbsp;&nbsp;&nbsp; DrawGun();<BR>&nbsp;&nbsp;&nbsp; 
DrawPlan();<BR>&nbsp;&nbsp;&nbsp; DrawStar();<BR>&nbsp;&nbsp;&nbsp; 
setcolor(LIGHTRED);/*define result words color*/<BR><BR>&nbsp;&nbsp;&nbsp; do{ 
/*程序主循环开始,用于运动飞机,方法是用异或的方式在屏幕上连续画出飞机 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
的图像,每画一次,新图像和来的位置相差两个像素点。这个值是可调的,值越大,飞机飞行的速度越快*/<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
putimage(x0-width2,y0-height-3*width1-i,buf,XOR_PUT);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
i+=2;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
putimage(x0-width2,y0-height-3*width1-i,buf,XOR_PUT);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
key=getch();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
if(y0-height-3*width1-i==0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
outtextxy(60,100,"Successfully!!! Press ESC to 
quit");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
if(key==ESC){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
if(y0-height-3*width1-i&gt;0){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
cleardevice();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
outtextxy(100,100,"Failue. What did you 
do?");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
outtextxy(130,300,"Press any key to 
quit.");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
getch();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
}<BR><BR>&nbsp;&nbsp;&nbsp; }while(key!=ESC);<BR><BR>&nbsp;&nbsp;&nbsp; 
free(buf);<BR>&nbsp;&nbsp;&nbsp; closegraph();<BR>&nbsp;&nbsp;&nbsp; return 
0;<BR><BR>}<BR>/*****************Install the graphics 
library***********************/<BR><BR>void 
InstallGraph(void)<BR>{<BR>&nbsp;&nbsp;&nbsp; int 
grdriver=DETECT;<BR>&nbsp;&nbsp;&nbsp; int grmode;<BR>&nbsp;&nbsp;&nbsp; int 
errorcode;<BR>&nbsp;&nbsp;&nbsp; char *errormsg;<BR><BR>&nbsp;&nbsp;&nbsp; 
registerbgidriver(EGAVGA_driver);<BR>&nbsp;&nbsp;&nbsp; 
registerbgifont(triplex_font);<BR>&nbsp;&nbsp;&nbsp; 
initgraph(&amp;grdriver,&amp;grmode,"");<BR><BR>&nbsp;&nbsp;&nbsp; 
errorcode=graphresult();<BR>&nbsp;&nbsp;&nbsp; 
errormsg=grapherrormsg(errorcode);<BR>&nbsp;&nbsp;&nbsp; 
if(errorcode!=grOk){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
printf("Graphics error: 
%s\n",errormsg);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any 
key to exit.\n");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
getch();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
exit(1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
}<BR>}<BR><BR>/************************Draw the star 
********************************/<BR><BR>void 
DrawStar(void)<BR>{<BR>&nbsp;&nbsp;&nbsp; int seed=2000;<BR>&nbsp;&nbsp;&nbsp; 
int i,dotx,doty,height,width,color,maxcolor;<BR><BR>&nbsp;&nbsp;&nbsp; 
maxcolor=getmaxcolor();<BR>&nbsp;&nbsp;&nbsp; 
width=getmaxx();<BR>&nbsp;&nbsp;&nbsp; 
height=getmaxy();<BR><BR>&nbsp;&nbsp;&nbsp; srand(seed);<BR>&nbsp;&nbsp;&nbsp; 
for(i=0;i&lt;250;i++){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
dotx=i+random(width-1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
doty=i+random(height-1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
color=random(maxcolor);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
setcolor(color);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
putpixel(dotx,doty,color);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
circle(dotx+1,doty+1,1);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
}<BR>&nbsp;&nbsp;&nbsp; srand(seed);<BR>}<BR>/****************Draw the bottom 
gun********************/<BR>void DrawGun(void)<BR>{<BR>&nbsp;&nbsp;&nbsp; int 
x0=300;<BR>&nbsp;&nbsp;&nbsp; int y0=430;<BR>&nbsp;&nbsp;&nbsp; int 
height=45;<BR>&nbsp;&nbsp;&nbsp; int rx=20;<BR>&nbsp;&nbsp;&nbsp; int 
ry=5;<BR>&nbsp;&nbsp;&nbsp; int rightx,righty,leftx,lefty;<BR>&nbsp;&nbsp;&nbsp; 
int centery1=30;<BR>&nbsp;&nbsp;&nbsp; 
rightx=righty=leftx=lefty=12;<BR><BR><BR>&nbsp;&nbsp;&nbsp; 
setcolor(LIGHTGREEN);<BR>&nbsp;&nbsp;&nbsp; 
ellipse(x0,y0,180,360,rx,ry);<BR>&nbsp;&nbsp;&nbsp; 
ellipse(x0,y0-height,0,360,rx,ry);<BR>&nbsp;&nbsp;&nbsp; 
line(x0+rx,y0,x0+rx,y0-height);<BR>&nbsp;&nbsp;&nbsp; 
line(x0-rx,y0,x0-rx,y0-height);<BR><BR>&nbsp;&nbsp;&nbsp; 
moveto(x0+rx,y0);<BR>&nbsp;&nbsp;&nbsp; 
lineto(x0+rx+rightx,y0+righty);<BR>&nbsp;&nbsp;&nbsp; 
moveto(x0+rx+rightx,y0+righty);<BR>&nbsp;&nbsp;&nbsp; 
lineto(x0+rx+rightx+10,y0+righty+10);<BR>&nbsp;&nbsp;&nbsp; 
circle(x0+rx+rightx+10,y0+righty+10,4);<BR><BR><BR>&nbsp;&nbsp;&nbsp; 
moveto(x0,y0+ry);<BR>&nbsp;&nbsp;&nbsp; 
lineto(x0,y0+centery1);<BR>&nbsp;&nbsp;&nbsp; 
moveto(x0,y0+centery1);<BR>&nbsp;&nbsp;&nbsp; 
lineto(x0,y0+centery1+10);<BR>&nbsp;&nbsp;&nbsp; 
circle(x0,y0+centery1+10,4);<BR><BR><BR>&nbsp;&nbsp;&nbsp; 
moveto(x0-rx,y0);<BR>&nbsp;&nbsp;&nbsp; 
lineto(x0-rx-leftx,y0+lefty);<BR>&nbsp;&nbsp;&nbsp; 
moveto(x0-rx-leftx,y0+lefty);<BR>&nbsp;&nbsp;&nbsp; 
lineto(x0-rx-leftx-10,y0+lefty+10);<BR>&nbsp;&nbsp;&nbsp; 
circle(x0-rx-leftx-10,y0+lefty+10,4);<BR><BR>&nbsp;&nbsp;&nbsp; 
line(x0-rx-leftx,y0+lefty,x0,y0+centery1);<BR>&nbsp;&nbsp;&nbsp; 
line(x0,y0+centery1,x0+rx+rightx,y0+righty);<BR>}<BR>/*****************Draw the 
plan fly to the sky***********************/<BR>void 
DrawPlan(void)<BR>{<BR><BR><BR>&nbsp;&nbsp;&nbsp; int 
size;<BR><BR>&nbsp;&nbsp;&nbsp; setcolor(LIGHTRED);<BR>&nbsp;&nbsp;&nbsp; 
setfillstyle(1,BLUE);<BR>&nbsp;&nbsp;&nbsp; 
ellipse(x0,y0-height,0,180,width1,3*width1);<BR><BR>&nbsp;&nbsp;&nbsp; 
moveto(x0+width1,y0); /*moveto center right side*/<BR>&nbsp;&nbsp;&nbsp; 
lineto(x0+width1,y0-height);<BR>&nbsp;&nbsp;&nbsp; 
moveto(x0+width1,y0);<BR>&nbsp;&nbsp;&nbsp; 
lineto(x0+width2,y0+y2);<BR><BR>&nbsp;&nbsp;&nbsp; moveto(x0-width1,y0); 
/*moveto center left side*/<BR>&nbsp;&nbsp;&nbsp; 
lineto(x0-width1,y0-height);<BR>&nbsp;&nbsp;&nbsp; 
moveto(x0-width1,y0);<BR>&nbsp;&nbsp;&nbsp; 
lineto(x0-width2,y0+y2);<BR><BR>&nbsp;&nbsp;&nbsp; 
moveto(x0+width2,y0+y3);/*moveto right bottom side*/<BR>&nbsp;&nbsp;&nbsp; 
lineto(x0+width2,y0+y1);<BR>&nbsp;&nbsp;&nbsp; 
moveto(x0+width2,y0+y3);<BR>&nbsp;&nbsp;&nbsp; 
lineto(x0+width1,y0+y2);<BR><BR>&nbsp;&nbsp;&nbsp; 
moveto(x0-width2,y0+y3);/*moveto left bottom side*/<BR>&nbsp;&nbsp;&nbsp; 
lineto(x0-width2,y0+y1);<BR>&nbsp;&nbsp;&nbsp; 
moveto(x0-width2,y0+y3);<BR>&nbsp;&nbsp;&nbsp; 
lineto(x0-width1,y0+y2);<BR><BR>&nbsp;&nbsp;&nbsp; moveto(x0,y0+y4); /*moveto 
the bottomest*/<BR>&nbsp;&nbsp;&nbsp; 
lineto(x0+width1,y0+y2);<BR>&nbsp;&nbsp;&nbsp; 
moveto(x0,y0+y4);<BR>&nbsp;&nbsp;&nbsp; 
lineto(x0-width1,y0+y2);<BR><BR>&nbsp;&nbsp;&nbsp; setfillstyle(2,LIGHTRED); 
/*fill the plan with a style */<BR>&nbsp;&nbsp;&nbsp; 
floodfill(x0,y0,LIGHTRED);<BR><BR>&nbsp;&nbsp;&nbsp; 
size=imagesize(x0-width2-1,y0-height-3*width1,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
x0+width2+1,y0+y4);<BR>&nbsp;&nbsp;&nbsp; 
buf=malloc(size);<BR>&nbsp;&nbsp;&nbsp; 
if(!buf){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("No enough 
memory!");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
exit(0);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; 
getimage(x0-width2,y0-height-3*width1,x0+width2,y0+y4,buf);<BR><BR>}</P>
<P align=center><FONT class=select12 color=#000000 
size=2>辽宁省铁岭师范高等专科学校微机室版权所有&copy;2002</FONT></P>
<P align=center><A href="javascript:window.close()">关闭窗口</A> </P>
<SCRIPT language=vbscript>

</SCRIPT>
</BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -