||
实例:怎样利用vba制作路径——完全非弹性碰撞动画
ppt的路径动画无法精确调整路径端点,因此本例用vba解决这一问题。
我们要做的效果是:左边的球中心运动到(9cm,10cm)时,两球立刻以原来速度的一半向右滑出画面。因此,需要对左边的球(m1)设置两段动画——碰撞前的运动较快,碰撞后的运动较慢,而右边的球(m2)只需要设置一段动画——但要和m1的第二段一起执行。
2、先把幻灯片页面设为32cm宽,然后进入vba环境,编写下面的程序。
Public Sub AddMotionPath() '绘制两个小球,并分别设置填充色 '设置左边小球碰撞前的动画效果 Set aniMotion = effNew.Behaviors.Add(msoAnimTypeMotion) '设置左边小球碰撞后的动画效果 Set aniMotion = effNew.Behaviors.Add(msoAnimTypeMotion) '设置右边小球碰撞后的动画效果 Set aniMotion = effNew.Behaviors.Add(msoAnimTypeMotion) |
程序一开始绘制两个小圆形,直径均为1cm,单位需要转化为磅,cm2p()函数见下面。
Private Function cm2p(cm As Single) As Single cm2p = cm * 28.35 End Function |
然后,程序添加3段向右运动的效果,AddEffect方法的Shape参数是指定应用动画的对象,effectID指定动画效果,Trigger指定动画发生时间(这里是单击幻灯片页面时发生),后面定义路径(字母M定义起点,M 0 0就是表示对象当前位置为起点,L表示直线运动到的位置,L 10/32 0表示横向向右运动幻灯片宽度的10/32,另外还有C、Z、X、H、V命令),再定义速度。以下定义碰撞以后m1和m2的运动效果,语句大体不变,只改变动画发生时间(m1的为前一动画结束时,m2与m1的第二段动画同时)和速度。
以上程序只需要执行一遍即设置完毕,然后可以删掉语句。
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-10-19 22:38
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社