Board logo

标题: [编程语言] 空气动力学原理,as2.0运用 [打印本页]

作者: Pelephone    时间: 2008-6-28 13:21     标题: 空气动力学原理,as2.0运用

相信未来几年内,as代会是富技术的领航``
贴一段as2.0的空气动力气源码给大家感受一个as的强大.


将下面代码粘到flash的第一帧,运行看看就看到效果了.

  1. //******
  2. //core graph studio
  3. //http://spaces.msn.com/coreg
  4. //CG 2006/3/5
  5. //******
  6. import flash.geom.Point;
  7. function initBones(r:Array):Array {
  8. var bones:Array = new Array();
  9. for (var i = 0; i<r.length; i++) {
  10. bones[i] = new Object();
  11. bones[i].s_point = new Point(0, 0);
  12. bones[i].e_point = new Point(0, r[i]);
  13. }
  14. return bones;
  15. }
  16. function setBones() {
  17. var n = bones.length-1;
  18. if (F.length>r[r.length-1]*2) {
  19. F.normalize(r[r.length-1]*2);
  20. }
  21. var len = F.length;
  22. while (n>=0) {
  23. var F_angle:Number = Math.atan2(F.y, F.x);
  24. var bone_angle:Number = Math.atan2(bones[n].e_point.y, bones[n].e_point.x);
  25. var d_angle:Number = F_angle-bone_angle;
  26. var f = Point.polar(F.length*Math.sin(d_angle), Math.PI/2+bone_angle);
  27. f.x *= 0.4;
  28. f.y *= 0.4;
  29. var new_point = bones[n].e_point.add(f);
  30. new_point.normalize(bones[n].e_point.length);
  31. bones[n].e_point = new_point.clone();
  32. //trace(n+"  "+bones[n].e_point+"  "+bones[n].e_point.length);
  33. F = Point.polar(F.length*Math.cos(d_angle)*f_xishu, bone_angle);
  34. if (F.length>r[n]*4) {
  35. F.normalize(r[n]*4);
  36. }
  37. n--;
  38. }
  39. for (var i = 1; i<bones.length; i++) {
  40. bones[i].s_point = bones[i-1].s_point.add(bones[i-1].e_point);
  41. //trace(bones[i].e_point)
  42. }
  43. clear();
  44. lineStyle(w[0], 0x4462EF, 50);
  45. moveTo(bones[0].s_point.x, bones[0].s_point.y);
  46. lineTo(bones[0].e_point.x, bones[0].e_point.y);
  47. for (var i = 1; i<bones.length; i++) {
  48. lineStyle(w[i], 0x4462EF, 50);
  49. lineTo(bones[i].s_point.x+bones[i].e_point.x, bones[i].s_point.y+bones[i].e_point.y);
  50. }
  51. }
  52. f_xishu = 0.95;
  53. r = [40, 100, 80, 60, 20, 40, 50];
  54. w = [100, 20, 25, 40, 80, 10, 5];
  55. bones = initBones(r);
  56. this.onEnterFrame = function() {
  57. 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);
  58. setBones();
  59. };
  60. //------
复制代码











呵呵,有回贴的话我再把代码注释敲上.
作者: khaki    时间: 2008-6-29 14:31

先看效果,再好好读一遍!




欢迎光临 花江边社区—论坛 (http://archive.huaclub.com/) Powered by Discuz! 7.2