软件频道>设计在线>Flash|平面网页Flash视频三维欣赏|设计专题教程素材| 群乐:Vista系统下载
您现在的位置: 天极网 > 软件频道 > 设计在线 > flash > 用Flash AS编写蝌蚪摆尾特效动画
全文

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

2007-05-18 15:50作者:yinggoing(闪吧 )出处:论坛整理责任编辑:Shiny

点击查看更多Flash精彩实例
http://design.yesky.com/flash/

  本文中我们用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



  如对于本文有任何疑问、意见以及建议,请在文章底部的留言板上留言。或者去天极设计在线主题社区讨论。

  更多精彩,尽在天极设计在线design.yesky.com!


电脑美术设计热门专区


设计软件视频教程大全

设计软件经典教程

设计人生——数码设计人访谈实录集
·软件论坛重装上线
·精彩网页素材
·照片处理专区
·设计软件经典教程集粹
  阅读关于 Flash AS 动画 技巧 实例 的全部文章

软件资讯·软件下载尽在天极软件

相关搜索:
关注此文读者还看过
热门关注
特别推荐
文章排行
本周
本月
最近更新
关于我们|About us|网站律师|天极服务|电子杂志|RSS订阅|加入我们|网站地图
TMG
Copyright (C) 1999-2009 Chinabyte.com, All Rights Reserved 版权所有 天极网络
商务联系、网站内容、合作建议:010-82657868
版权声明 在线提交意见反馈 渝ICP证B2-20030003号
经营性网站备案信息 网警备案 中国网站排名
天极传媒:天极网|比特网|IT专家网|IT商网|52PK游戏网|IT分众