Flash AS实现的蝌蚪摆尾动画的教程
平面设计 2021-07-03 14:34www.168986.cn平面设计培训
本例介绍使用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
};
s ()
#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
场景里代码
复制代码
代码如下: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
};
s ()
#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制作可爱的亲嘴猪动画效果
下一篇:Flash 脚本游戏开发教程第八课
平面设计师
- 平面设计图怎么画 小学生画平面图
- 平面设计内容怎么写 平面设计的求职意向怎么写
- 平面设计图手绘 平面设计图手绘家具
- 平面设计多久能出师 平面设计要多久
- 女生做ui设计师有多累 女生为什么学ui的人很惨
- 哪里有学平面设计的学校 想学平面设计去哪里学
- 初学平面设计用哪个软件 平面设计初学者必备的
- 0基础学平面设计要多久 0基础自学平面设计
- 平面设计手绘培训 平面设计师培训班学费多少钱
- ui工作好找工作吗 ui好不好找工作
- 女生学室内设计吃香吗
- ps平面设计自学教程 平面设计ps入门教程
- 平面设计基础知识大全 平面设计基本常识
- 平面设计基础教学视频 平面设计教学零基础入门
- 平面设计基础教学 平面设计基础教学平时作业
- ui设计主要是学什么 ui设计一般是学什么