1、多媒体课程实训报告 CENTAL SOUTH UNIVERSITY OF FORESTRYAND TECHNOLOGY中南林业科技大学课 程 实 训 报 告课 程: 多媒体技术及应用 姓 名: 朱军 学 号: 20094204 专 业: 计算机科学与技术 指导教师: 陈 宇 拓 日 期: 2011年6月21日 实训题目一利用编程实现动画时钟一课程设计目的: 希望通过本次课程实训设计能够对多媒体编程有个大致了解熟悉使用一些常用的多媒体编程中常用到的函数插件等等二设计方法:1. 主要采用vb6.0在windows平台下实现编程。三.实训步骤 1.打开vb6.0 新建一个项目 选择标准EXE. 2.
2、 新建一个窗体在窗体中加入timer控件 设定interval 900. 3. 双击进入代码编辑区输入以下代码 编写时钟表盘效果。4. 整体效果运行预览。四、算法用Load命令建立原始Line控制的14个拷贝(因为表盘有12个点和时、分、秒共15个Line),该控制数组每一个实例的端点坐标属性设置为每条线在时钟表盘上的适当位置。这些拷贝中大多数只放置一次,而3个Line控制每秒钟更新一次,产生时钟指针移动的感觉。五、程序代码如下 Option ExplicitConst PI = 3.1415926Dim BaseX As Integer, BaseY As Integer, R As Int
3、egerDim r1 As Integer, r2 As Integer, r3 As IntegerPrivate Sub Init()Dim i As Integer BaseX = Me.ScaleWidth / 2 BaseY = Me.ScaleHeight / 2 R = IIf(BaseX BaseY, BaseY * 0.8, BaseY * 0.8) r1 = R * 0.2 r2 = R * 0.1 r3 = R * 0.05 For i = 0 To 360 Step 6 If i Mod 30 = 0 Then 时 Me.DrawWidth = 2 DrawLine B
4、aseX + (R - 3) * Sin(i * PI / 180), BaseY - (R - 3) * Cos(i * PI / 180), BaseX + (R - 8) * Sin(i * PI / 180), BaseY - (R - 8) * Cos(i * PI / 180), 3 Else 分 Me.DrawWidth = 2 Me.PSet (BaseX + (R - 3) * Sin(i * PI / 180), BaseY - (R - 3) * Cos(i * PI / 180) End If Next Me.DrawWidth = 1 Me.Circle (BaseX
5、, BaseY), REnd Sub绘制指针Private Sub DrawClock()Dim Second As IntegerDim Minute As IntegerDim Hours As Integer Second = DatePart(s, Time) Minute = DatePart(n, Time) Hours = DatePart(h, Time) If Hours 12 Then Hours = Hours - 12 End If Me.DrawWidth = 1 Me.Circle (BaseX, BaseY), 4 DrawLine BaseX - r1 * Si
6、n(Second * PI / 30), BaseY + r1 * Cos(Second * PI / 30), BaseX + (R - 10) * Sin(Second * PI / 30), BaseY - (R - 10) * Cos(Second * PI / 30), 0 DrawLine BaseX - r2 * Sin(Minute * PI / 30), BaseY + r2 * Cos(Minute * PI / 30), BaseX + R * 0.8 * Sin(Minute * PI / 30), BaseY - R * 0.8 * Cos(Minute * PI /
7、 30), 1 DrawLine BaseX - r3 * Sin(Hours + Minute / 60) * PI / 6), BaseY + r3 * Cos(Hours + Minute / 60) * PI / 6), BaseX + R * 0.6 * Sin(Hours + Minute / 60) * PI / 6), BaseY - R * 0.6 * Cos(Hours + Minute / 60) * PI / 6), 2End Sub画线函数Private Sub DrawLine(x1 As Integer, y1 As Integer, x2 As Integer,
8、 y2 As Integer, Flag As Integer)Static OldSX1 As Integer, OldSX2 As Integer, OldSY1 As Integer, OldSY2 As IntegerStatic OldMX1 As Integer, OldMX2 As Integer, OldMY1 As Integer, OldMY2 As IntegerStatic OldHX1 As Integer, OldHX2 As Integer, OldHY1 As Integer, OldHY2 As Integer Select Case Flag Case 0
9、Me.DrawWidth = 1 Me.Line (OldSX1, OldSY1)-(OldSX2, OldSY2), Me.BackColor Me.Line (x1, y1)-(x2, y2) OldSX1 = x1 OldSX2 = x2 OldSY1 = y1 OldSY2 = y2 Case 1 Me.DrawWidth = 2 Me.Line (OldMX1, OldMY1)-(OldMX2, OldMY2), Me.BackColor Me.Line (x1, y1)-(x2, y2) OldMX1 = x1 OldMX2 = x2 OldMY1 = y1 OldMY2 = y2
10、 Case 2 Me.DrawWidth = 3 Me.Line (OldHX1, OldHY1)-(OldHX2, OldHY2), Me.BackColor Me.Line (x1, y1)-(x2, y2) OldHX1 = x1 OldHX2 = x2 OldHY1 = y1 OldHY2 = y2 Case Else Me.Line (x1, y1)-(x2, y2) End SelectEnd SubPrivate Sub Form_Resize() Me.Cls Call InitEnd SubPrivate Sub Timer1_Timer() Call DrawClockEn
11、d Sub六、总结 通过本次实训,初步掌握了模拟动态时钟的设计,对vb时间控件及使用有了大致了解,为进一步学习奠定了基础。实训题目二金鱼游水逐食一课程设计目的: 希望通过本次课程实训设计能够对flash动画制作有更进一步的认识。并会利用其制作比较复杂的动画。二设计方法:2. 主要采用flash在windows平台下实现。三.实训步骤 1.打开flash 新建一个flash文本 2.首先制作金鱼身体的各个部位。头部 躯部 尾部 分别做成原件存放在库中供使用 3. 选定图层一的第一帧 在动作下输入代码实现让金鱼游动。4. 整体效果运行预览。 脚本动画代码如下var frame=0;var num=
12、25;var fishColors=0xff0000,0xff9900,0,0x99ff00,0x9900ff,0x9999ff;function initFish(level,fishColor) var pArray=new Array(); var myColor; pArray.dis=2.5;/金鱼身体每节的距离 pArray.direction=-90; /金鱼头的朝向 pArray.v=2; pArray.v1=pArray.v; pArray.vibration=0; pArray.state=1; /自由活动 pArray.distX=random(550); pArray.
13、distY=random(400); pArray.targetFishs=new Array(); pArray.targetIndex; /初始化每节坐标 var randX=random(550); for(var i=0;inum;i+) var obj=new Object; obj.x=randX; obj.y=100+i*pArray.dis; pArrayi=obj; /初始化身体每节的图片 for(var i=0;inum;i+) var c; if(i=0) c=this.attachMovie(head,c+(level+i),level+i); c._alpha=100
14、; c._width=c._height=20; myColor=new Color(c); myColor.setRGB(fishColor); else c=this.attachMovie(body,c+(level+i),level+i); c._alpha=50; c._xscale=c._yscale=20; myColor=new Color(c); myColor.setRGB(fishColor); c._x=pArrayi.x; c._y=pArrayi.y; c.gotoAndStop(i+1); pArrayi.obj=c; for(var i=0;inum;i+) p
15、Arrayi.obj._x=pArrayi.x; pArrayi.obj._y=pArrayi.y; pArray.addTarget=function (tFish) pArray.targetFishs.push(tFish); /鱼的动作 pArray.step=function () var rand=random(300); if(rand=1) pArray.state=rand; if(pArray.targetFishs.length=0 & rand=3) pArray.state=1; /如果只有一条鱼,那么不能追逐其它鱼 if(pArray.state=3) /如果状态转
16、换为追踪其他鱼,那么随机挑选一个目标鱼 pArray.targetIndex=random(pArray.targetFishs.length); if(pArray.v=2 & random(200)=1) /欢快 pArray.v=5; if(pArray.v=5 & random(50)=1) /悠闲 pArray.v=2; if(pArray.state=1 & random(100)=1) /自由活动时更改移动方向 pArray.distX=random(550); pArray.distY=random(400); if(1) var d,dAngle; var x1,x2,y1,
17、y2; x1=pArray0.x; y1=pArray0.y; switch(pArray.state) case 1:/自由活动 x2=pArray.distX; y2=pArray.distY; break; case 2:/觅食 x2=seed._x; y2=seed._y; break; case 3: /追逐其它的鱼 x2=pArray.targetFishstargetIndex0.x; y2=pArray.targetFishstargetIndex0.y; break; d=Math.sqrt(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2); if(pArray.
18、state=1 & d20.0) /自由活动时距离目标点很近的时候更换目标点 pArray.distX=random(550); pArray.distY=random(400); if(pArray.state=3 & d10.0) /离目标鱼足够近的时候 pArray.state=1; / trace(ok); dAngle=-Math.asin(y2-y1)/d)/Math.PI*180; if(x2-x10) dAngle+=2*(90-dAngle); if(x2-x10 & dAngle0) dAngle-=2*(-90+dAngle); if(dAngle360) pArray.
19、direction-=360; if(pArray.direction180) dAngle=dAngle-360; if(dAngle=7) pArray.direction+=1*pArray.v; /游泳时有规律的摆动 else direction-=1*pArray.v; if(random(60)=1) /改变速度 pArray.v1=pArray.v+random(pArray.v); pArray0.x+=pArray.v1*Math.cos(pArray.direction*Math.PI/180) pArray0.y+=pArray.v1*Math.sin(pArray.di
20、rection*Math.PI/180); pArray0.obj._rotation=pArray.direction+90; /计算身体位置 for(var i=1;inum;i+) var x0,y0,x1,y1,d; x0=pArrayi-1.x; y0=pArrayi-1.y; x1=pArrayi.x; y1=pArrayi.y; d=Math.sqrt(x0-x1)*(x0-x1)+(y0-y1)*(y0-y1); pArrayi.x=x0+pArray.dis/d*(x1-x0); pArrayi.y=y0+pArray.dis/d*(y1-y0); for(var i=0;i
21、=0;i-) pArrayi.obj._x=pArrayi.x; pArrayi.obj._y=pArrayi.y; pArrayi.obj._rotation=pArrayi-1.obj._rotation; if (pArray.state=2 & pArray0.obj.hitTest(seed) /吃食物 if(random(5)=1) seed._x=random(550); seed._y=random(400); seed.vx=0; seed.vy=0; pArray.vibration=0; pArray.v=2; else var direct; direct=pArray
22、.direction+random(40)-20;seed.vx=3*pArray.v1*Math.cos(direct/180*Math.PI); seed.vy=3*pArray.v1*Math.sin(direct/180*Math.PI); pArray.vibration=40; pArray.v=4; /end if /end function return pArray;var fishs;function initFishs() var fishNumber; fishs=new Array(); for(var i=1;i1000;i+) removeMovieClip(c+
23、i); fishNumber=int(comFishNum.getValue(); for(var i=0;ifishNumber;i+) var fish=initFish(i*31+1,fishColorsi); fishsi=fish; for(var i=0;ifishNumber;i+) for(var j=0;jfishNumber;j+) if(i!=j) fishsi.addTarget(fishsj);/食物处理var seed=this.attachMovie(c,c+2000,0);seed._x=random(550);seed._y=random(400);seed.
24、_width=seed._height=6;seed.vx=seed.vy=0;this.onMouseDown=function() seed._x=_xmouse; seed._y=_ymouse;this.onEnterFrame=function () frame+; seed._x+=seed.vx; seed._y+=seed.vy; if(seed._x550) seed.vx=-seed.vx; if(seed._y400) seed.vy=-seed.vy; seed.vx*=0.8; seed.vy*=0.8; for(var i=0;ifishs.length;i+) fishsi.step(); initFishs(); 四、总结 通过本次实训,掌握了如何利用flash的脚本命令完成各原件的定义实现各部件的动画。使动画显示的效果更逼真。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1