求一简单的C语言动画程序。

求一简单的C语言动画程序。,第1张

C语言动画程序

#include <math.h>

#include <stdio.h>

#include <graphics.h>

#include <dos.h>

#define pi 3.1415926535

double ca3mm1(double m1,double m2)

double ca3fm1(double cosine,double sine)

double ca5fm2(double a6m,double a5m,double a4m,double a4f,int shang)

double ca6fm2(double a4m ,double a4f,double a5m , double a5f)

char inbox(int x,int y,int x1,int y1)

char buf()

main()

{

double m=3.0

double xo=100.0,yo=200.0,a1=30.0,t1=pi

double xc=xo+m*a1,yc=yo

double a2=8.0,a3,a4=25.0,a5=30.0,a6=20.0,a7=35.0

double t2,t3,t4,t5,t6,t7

double xo1=xo+m*150,yo1=yo

double xc1=xo1-m*a1,yc1=yo1

double i,j,k

double l1

double n=116.1,nt

initscreen()

setfillstyle(SOLID_FILL,DARKGRAY)

bar(0,0,640,480)

mybutton(10,10,"BEGIN",1,0)

mybutton(500,10,"EXIT",1,0)

line(0,69,640,69)

mouseinit()

changemousecross()

setmousexy(320,20)

mouseshow()

setmousearea(0,0,640,60)

do{

if(inbox(10,10,70,26)&&button()==1)

{mousehide() mybutton(10,10,"BEGIN",0,0) mouseshow() mousehold() mousehide() mybutton(10,10,"BEGIN",1,7) mouseshow() break }

if(inbox(500,10,555,26)&&button()==1)

{mousehide() mybutton(500,10,"EXIT",0,0) mouseshow() mousehold() mousehide() mybutton(500,10,"EXIT",1,7) mouseshow() exit(0) }

if(buf()==56)

for(i=0i<10000i++){

switch (buf()){

case 18:{

mousehide()

mybutton(500,10,"EXIT",0,0)

mouseshow()

delay(4000)

mousehide()

mybutton(500,10,"EXIT",1,7)

mouseshow()

exit(0)

}

case 48: {

mousehide()

mybutton(10,10,"BEGIN",0,0)

mouseshow()

delay(4000)

mousehide()

mybutton(10,10,"BEGIN",1,7)

mouseshow()

goto run

}

default:break

}

}

}while(1)

run:

drawjijia(xo,yo,1)

drawjijia(xc,yc,1)

drawjijia(xo1,yo1,1)

drawjijia(xc1,yc1,1)

setwritemode(1)

do{

for(i=0i<360.0i+=1.0)

{

t2=i

a3=ca3mm1(a1*cos(t1)+a2*cos(t2*pi/180.0),a1*sin(t1)+a2*sin(t2*pi/180.0))

t3=ca3fm1(a1*cos(t1)+a2*cos(t2*pi/180.0),a1*sin(t1)+a2*sin(t2*pi/180.0))

a4=a3

t4=t3

t5=ca5fm2(a6,a5,a4,t4,0)

t6=ca6fm2(a4,t4,a5,t5)

t7=t6-90.0

l1=xc1-xc-2*m*a7*cos(t7*pi/180)

nt=(asin(l1/2/(n/2))*180/pi)-90.0

drawline(xo,yo,a2,t2,m,LIGHTGRAY)

drawline(xo+m*a2*cos(t2*pi/180),yo-m*a2*sin(t2*pi/180),a5,t5,m,LIGHTGRAY)

drawline(xc,yc,a6,t6,m,LIGHTGRAY)

drawline(xc,yc,a7,t7,m,LIGHTGRAY)

drawline1(xo1,yo1,a2,t2,m,LIGHTGRAY)

drawline1(xo1+m*a2*cos((180-t2)*pi/180),yo1-m*a2*sin((180-t2)*pi/180),a5,t5,m,LIGHTGRAY)

drawline1(xc1,yc1,a6,t6,m,LIGHTGRAY)

drawline1(xc1,yc1,a7,t7,m,LIGHTGRAY)

for(j=-1j<20j++)

{ drawline(xc+m*a7*cos(t7*pi/180),(yc-m*a7*sin(t7*pi/180)-j*n*sin(nt*pi/180)),n,nt,1.0,GREEN)

drawline1(xc1-m*a7*cos(t7*pi/180),(yc1-m*a7*sin(t7*pi/180)-j*n*sin(nt*pi/180)),n,nt,1.0,DARKGRAY)

}

delay(300)

drawline(xo,yo,a2,t2,m,LIGHTGRAY)

drawline(xo+m*a2*cos(t2*pi/180.0),yo-m*a2*sin(t2*pi/180.0),a5,t5,m,LIGHTGRAY)

drawline(xc,yc,a6,t6,m,LIGHTGRAY)

drawline(xc,yc,a7,t7,m,LIGHTGRAY)

drawline1(xo1,yo1,a2,t2,m,LIGHTGRAY)

drawline1(xo1+m*a2*cos((180-t2)*pi/180),yo1-m*a2*sin((180-t2)*pi/180),a5,t5,m,LIGHTGRAY)

drawline1(xc1,yc1,a6,t6,m,LIGHTGRAY)

drawline1(xc1,yc1,a7,t7,m,LIGHTGRAY)

for(j=-1j<20j++)

{ drawline(xc+m*a7*cos(t7*pi/180),(yc-m*a7*sin(t7*pi/180)-j*n*sin(nt*pi/180)),n,nt,1.0,GREEN)

drawline1(xc1-m*a7*cos(t7*pi/180),(yc1-m*a7*sin(t7*pi/180)-j*n*sin(nt*pi/180)),n,nt,1.0,DARKGRAY)

}

setwritemode(0)

if(inbox(500,10,555,26)&&button()==1)

{mousehide() mybutton(500,10,"EXIT",0,0) mouseshow() mousehold() mousehide() mybutton(500,10,"EXIT",1,7) mouseshow() exit(0) }

if(buf()==56)

for(k=0k<10000k++){

switch (buf()){

case 18:{

mousehide()

mybutton(500,10,"EXIT",0,0)

mouseshow()

delay(4000)

mousehide()

mybutton(500,10,"EXIT",1,7)

mouseshow()

exit(0) }

default:break

}

}

setwritemode(1)

}

}while(1)

}

drawline(double xo,double yo,double mo,double fujiao,double m,int color)

{

double x,y

x=(xo+m*mo*cos(fujiao*pi/180))

y=(yo-m*mo*sin(fujiao*pi/180))

setcolor(color)

line (xo,yo,x,y)

}

drawline1(double xo,double yo,double mo,double fujiao,double m,int color)

{

double x,y

x=(xo-m*mo*cos(fujiao*pi/180))

y=(yo-m*mo*sin(fujiao*pi/180))

setcolor(color)

line (xo,yo,x,y)

}

drawjijia(double x,double y,int shang)

{

setcolor(RED)

if (shang==1){

circle(x,y,3)

line(x-3.0,y+3.0,x-15.0,y+20.0)

moveto(x-15,(int)(y+20))

lineto((int)(x+15),(int)(y+20))

moveto((int)(x+15),(int)(y+20))

lineto(x+3,y+3)}

setcolor(RED)

if (shang==0){

circle((int)x,(int)y,3)

line (x-3,y-3,x-15,y-20)

moveto(x-15,y-20)

lineto(x+15,y-20)

moveto(x+15,y-20)

lineto(x+3,y-3)

}

}

double ca3mm1(double m1,double m2)

{

double temp

temp = sqrt(m1*m1 + m2*m2)

return(temp)

}

double ca3fm1(double cosine,double sine)

{

float temp

if (sine > 0 && cosine > 0)

temp = atan(sine / cosine) * 180 / pi

if (sine > 0 && cosine < 0)

temp = (atan(sine / cosine) + pi) * 180 / pi

if (sine < 0 && cosine < 0)

temp = (atan(sine / cosine) + pi) * 180 / pi

if (sine < 0 && cosine > 0)

temp = (atan(sine / cosine) + 2 * pi) * 180 / pi

return(temp)

}

double ca5fm2(double a6m,double a5m,double a4m,double a4f,int shang)

{

double temp,sine1,cosine1

cosine1 = (a6m *a6m - a4m *a4m - a5m*a5m) / (2 * a4m * a5m)

sine1 = sqrt(1 - cosine1 *cosine1)

if (shang==0)

sine1 = sine1*(-1)

if (sine1 > 0 && cosine1 > 0)

temp = a4f + (atan(sine1 / cosine1) * 180 / pi)

if (sine1 > 0 && cosine1 < 0)

temp = a4f + ((atan(sine1 / cosine1) + pi) * 180 / pi)

if (sine1 < 0 && cosine1 < 0)

temp = a4f + ((atan(sine1 / cosine1) + pi) * 180 / pi)

if (sine1 < 0 && cosine1 > 0)

temp = a4f + ((atan(sine1 / cosine1) + 2 * pi) * 180 / pi)

return(temp)

}

double ca6fm2(double a4m ,double a4f,double a5m , double a5f)

{

double temp,sine1,cosine1

sine1 = a4m * sin(a4f * pi / 180) + a5m * sin(a5f * pi / 180)

cosine1 = a4m * cos(a4f * pi / 180) + a5m * cos(a5f * pi / 180)

if (sine1 > 0 && cosine1 > 0)

temp = (atan(sine1 / cosine1) * 180 / pi)

if (sine1 > 0 && cosine1 < 0)

temp = ((atan(sine1 / cosine1) + pi) * 180 / pi)

if (sine1 < 0 && cosine1 < 0)

temp = ((atan(sine1 / cosine1) + pi) * 180 / pi)

if (sine1 < 0 && cosine1 > 0)

temp = ((atan(sine1 / cosine1) + 2 * pi) * 180 / pi)

return(temp)

}

initscreen()

{

int gd=DETECT,gm

registerbgidriver(EGAVGA_driver)

initgraph(&gd,&gm,"")

}

因为C的图形处理功能太一般,不便于创作大型动画。制作动画用flash。

flash制作动画:

打开Flash,点击【文件】→【新建】,在打开的“新建”窗口中选择“Flash文件(ActiveScript 3.0)“,然后点击”确定“创建空白文档。

点击【插入】→【新建元件】,在打开的”新建元件“窗口中,将名称设置为”运动的小人“,勾选”影片剪消枣辑“,然后点击”确定“按钮。

点击【文件】→【导入】→【导入到库】,然后在打开的”导入到库“窗口中,选择事先准备好的小人走动姿势图片,全部选择并点击”打开“按钮,导入到库。

图层1 的第一帧,把库中的“Result0”拖动到场景中。

点击“时间轴”上的“新建图层”按钮,创建图层2,然后在图层2的第5帧处,点击【插入】→【关键帧告游】,袜桥销把库中的“Result1”拖动到场景中。

利用同样的原理,将”Result2“、 ”Result3“和”Result4“分别到图层3、图层4和图层5中,对应的帧分别为10、15和20处。

最后调整各个图层图像的延续时间。至此,运动的小人影片剪辑制作完成。

切换至主场景中,使主场景处于活动状态,点击”属性“面板中的”大小“按钮,将场景的大小设置为”800*300“,同时将背景色设置为”黑色“点击”确定“按钮。

从库中将”运动的小人“影片剪辑拖动到场景左边外边。

然后在”时间轴“第30帧处,点击【插入】→【时间轴】→【关键帧】,在30帧处插入关键帧,然后将小人从场景的左侧外面拖动到场景右侧外面。至此,整个动画设置完成。

在1到30帧之间鼠标右击,选择”创建补间动画“。

最后按下键盘组合键”CTRL+Enter“进行测试。如果感觉小人运动不规律,可适当将1至30帧的距离调整的稍微大一些,直到满意为止。

1.可以考虑用Turbo C的绘图早知御函数(附加graphic.h库)或者用opengl+glut等来实现。 2.前者一般就是纯粹的画点画线。网上也能找到教程。3.主要说一下后者。可以导入图片,并且二维、三维动画都可以做,甚至是用来开发游戏。后者可以用vc6.0或者vs2005来开发。跨平台。参考教程: http://www.owlei.com/DancingWind/看你的描述要做比较偏数学的东西,那你自己得弄明白如何去实现绘制算法。要实现的动画本身而搭的基本框架不猛明会很复杂的,可能100行代码都不用。4.另外还有opencv、GDI之类的可能更适合二维图像处理库,但我自己陆岩不是很了解了,你也可以查一查用哪种绘图库比较适合你。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12562305.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存