- 积分
- 81
- 花江币
- 41 元
|
相信未来几年内,as代会是富技术的领航``
贴一段as2.0的空气动力气源码给大家感受一个as的强大.
将下面代码粘到flash的第一帧,运行看看就看到效果了.
-
- //******
- //core graph studio
- //http://spaces.msn.com/coreg
- //CG 2006/3/5
- //******
- import flash.geom.Point;
- function initBones(r:Array):Array {
- var bones:Array = new Array();
- for (var i = 0; i<r.length; i++) {
- bones[i] = new Object();
- bones[i].s_point = new Point(0, 0);
- bones[i].e_point = new Point(0, r[i]);
- }
- return bones;
- }
- function setBones() {
- var n = bones.length-1;
- if (F.length>r[r.length-1]*2) {
- F.normalize(r[r.length-1]*2);
- }
- var len = F.length;
- while (n>=0) {
- var F_angle:Number = Math.atan2(F.y, F.x);
- var bone_angle:Number = Math.atan2(bones[n].e_point.y, bones[n].e_point.x);
- var d_angle:Number = F_angle-bone_angle;
- var f = Point.polar(F.length*Math.sin(d_angle), Math.PI/2+bone_angle);
- f.x *= 0.4;
- f.y *= 0.4;
- var new_point = bones[n].e_point.add(f);
- new_point.normalize(bones[n].e_point.length);
- bones[n].e_point = new_point.clone();
- //trace(n+" "+bones[n].e_point+" "+bones[n].e_point.length);
- F = Point.polar(F.length*Math.cos(d_angle)*f_xishu, bone_angle);
- if (F.length>r[n]*4) {
- F.normalize(r[n]*4);
- }
- n--;
- }
- for (var i = 1; i<bones.length; i++) {
- bones[i].s_point = bones[i-1].s_point.add(bones[i-1].e_point);
- //trace(bones[i].e_point)
- }
- clear();
- lineStyle(w[0], 0x4462EF, 50);
- moveTo(bones[0].s_point.x, bones[0].s_point.y);
- lineTo(bones[0].e_point.x, bones[0].e_point.y);
- for (var i = 1; i<bones.length; i++) {
- lineStyle(w[i], 0x4462EF, 50);
- lineTo(bones[i].s_point.x+bones[i].e_point.x, bones[i].s_point.y+bones[i].e_point.y);
- }
- }
- f_xishu = 0.95;
- r = [40, 100, 80, 60, 20, 40, 50];
- w = [100, 20, 25, 40, 80, 10, 5];
- bones = initBones(r);
- this.onEnterFrame = function() {
- F = new Point(_xmouse-bones[bones.length-1].s_point.x-bones[bones.length-1].e_point.x, _ymouse-bones[bones.length-1].s_point.y-bones[bones.length-1].e_point.y);
- setBones();
- };
- //------
复制代码
呵呵,有回贴的话我再把代码注释敲上. |
|