设为首页  
联系我们  
加入收藏  
IT动态 网页制作 操作系统 图形图象 冲浪宝典 网络安全 软件教学 认证考试 互联网 数据通信 视频通信 网络编程
您的位置: 首页 >> >> 图形图象 >> FLASH教程 >> 用Flash AS编写蝌蚪摆尾特效动画
精品推荐
FLASH教程点击TOP10
·在线设计制作Flash动画小电影
·用Flash AS编写蝌蚪摆尾特效动画
·Flash电子书鼠标拖拽翻页效果原理分析
·用Flash轻松制作鼠标点击发散特效动画
·网页中插入透明Flash的方法和技巧
·用Flash MX软件制作遥控小汽车
·我的世界杯:FLASH制作滚动足球动画
·在Flash动态文本框中加载HTML格式文本
·Flash实例精通:教你制作交互式二合一按钮
·Flash常用ActionScript控制语句基本用法
图形图象点击TOP10
·Photoshop把自己的照片放在衣服上面
·AutoCAD三维基础实例教程
·用AUTOCAD五个简单命令绘莲花图案
·Photoshop打造美女漂亮的脸
·用Photoshop制作无缝拼接背景图
·Photoshop帮漂亮美女换衣服
·彩虹初现 Photoshop设计奇幻风格的壁纸
·3DSMAX中玻璃材质制
·用3DSMAX打造漂亮的水晶十字项链
·3DS MAX粒子系统应用实例:轻松打造火焰特效
精选专题

用Flash AS编写蝌蚪摆尾特效动画

作者: 来源:http://www.gz183.com.cn 时间:2007-6-8 9:49:46

  本文中我们用Flash 的 AS代码来编写一个蝌蚪自由摆尾游动的动画。

  场景里代码:

Object.environment = this;
Math.prototype.degrees = function (r)
{
    return (r * 180 / 3.141593E+000);
};
maxtents = 3;
this.onEnterFrame = function ()
{
    if (!random(30) && tents < maxtents)
    {
        var nombre = "tent" + String(depth++);
        var neo = this.attachMovie("tentacle", nombre, depth);
        neo._x = random(600);
        neo._y = 370;
        neo.theta = 270;
        ++tents;
    } // end if
};
stop ()

  MC里的代码:

#initclip 1
function TentacleClass()
{
    this.numNodes = 27;
    this.head = 2 + random(4);
    this.girth = 8 + random(12);
    this.speedCoefficient = 9.000000E-002 + random(10) / 50;
    this.friction = 9.000000E-001 + random(10) / 100;
    this.muscleRange = 20 + random(50);
    this.muscleFreq = 1.000000E-001 + random(100) / 250;
    this.generateNodes();
    this.onEnterFrame = this.move;
} // End of the function
TentacleClass.prototype = new MovieClip();
TentacleClass.prototype.generateNodes = function ()
{
    this.node = new Array();
    var n = 0;
    while (n < this.numNodes)
    {
        var point = {x: 0, y: 0};
        this.node.push(point);
        ++n;
    } // end while
};
TentacleClass.prototype.move = function ()
{
    this.tv = this.tv + 5.000000E-001 * (Math.random() - Math.random());
    this.theta = this.theta + this.tv;
    this.tv = this.tv * this.friction;
    this.node[0].x = this.head * Math.cos(1.745329E-002 * this.theta);
    this.node[0].y = this.head * Math.sin(1.745329E-002 * this.theta);
    this.count = this.count + this.muscleFreq;
    this.thetaMuscle = this.muscleRange * Math.sin(this.count);
    this.node[1].x = -this.head * Math.cos(1.745329E-002 * (this.theta + this.thetaMuscle));
    this.node[1].y = -this.head * Math.sin(1.745329E-002 * (this.theta + this.thetaMuscle));
    var i = 2;
    while (i < this.numNodes)
    {
        var dx = this.node.x - this.node[i - 2].x;
        var dy = this.node.y - this.node[i - 2].y;
        var d = Math.sqrt(dx * dx + dy * dy);
        this.node.x = this.node[i - 1].x + dx * this.girth / d;
        this.node.y = this.node[i - 1].y + dy * this.girth / d;
        if (i == 2)
        {
            this._x = this._x - dx * this.speedCoefficient;
            this._y = this._y - dy * this.speedCoefficient;
            if (this._x + this._width < 0 this._x - this._width > 600 this._y + this._height < 0 this._y - this._height > 400)
            {
                --Object.environment.tents;
                this.removeMovieClip();
            } // end if
        } // end if
        ++i;
    } // end while
    this.clear();
    this.moveTo(this.node[1].x, this.node[1].y);
    var i = 2;
    while (i < this.numNodes)
    {
        this.lineStyle(int(this.numNodes - i) * (this.numNodes - i) / 20, 16777215, 100);
        this.lineTo(this.node.x, this.node.y);
        ++i;
    } // end while
};
Object.registerClass("tentacle", TentacleClass);
#endinitclip


用Flash AS编写蝌蚪摆尾特效动画 相关文章:
用Flash AS编写蝌蚪摆尾特效动画 相关软件: