应用思考-教育技术论坛

标题: 抛物线运动物理课件制作 [打印本页]

作者: etthink    时间: 2010-5-31 23:59
标题: 抛物线运动物理课件制作
原文地址:http://www.lxlong.net/?p=1793
http://www.lxlong.net/wp-content/uploads/2010/05/paoWuYunDong.swf

  1. var oldX:Number = ball_mc.x;
  2. var oldY:Number = ball_mc.y;
  3. var v:Number;
  4. var g:Number;
  5. var time:Number;
  6. var visi:Boolean = true;
  7. var b:Boolean;
  8. var drawSp:Shape=new Shape();
  9. var xArr:Array = [];
  10. var yArr:Array = [];
  11. var ind:uint;
  12. addChild(drawSp);
  13. for (var i:int=0; i<=30; i++)   {
  14. graphics.lineStyle(0,0xcccccc);
  15. if (i % 5 == 0)    {
  16.   graphics.lineStyle(0,0×000000);
  17. }
  18. graphics.moveTo(100+i*20,50);
  19. graphics.lineTo(100+i*20,50+30*20);
  20. graphics.moveTo(100,50+i*20);
  21. graphics.lineTo(100+30*20,50+i*20);
  22. }
  23. start_btn.addEventListener(MouseEvent.CLICK,startFunc);
  24. function startFunc(e)   {
  25. addEventListener(Event.ENTER_FRAME,onFrame);
  26. b = true;
  27. xball_mc.x = ball_mc.x = oldX;
  28. yball_mc.y = ball_mc.y = oldY;
  29. v = Number(input_txt.text);
  30. g = 1.5;
  31. time = 0;
  32. xArr = [];
  33. yArr = [];
  34. drawCircle(ball_mc.x,ball_mc.y);//每次先在起点处画个点
  35. xArr[0]=100;
  36. yArr[0]=50;//每次把这个位置预先放入坐标数组的首位
  37. }
  38. function onFrame(e)   {
  39. time++;
  40. time_txt.text=(Math.round(time*10)/100).toString();
  41. ball_mc.x =100+  v * (time  );
  42. ball_mc.y +=  g * (time / 10) * (time / 10) / 2/3.3;
  43. xball_mc.x =100+ v * (time )
  44. yball_mc.y +=  g * (time / 10 )*( time / 10) / 2/3.3;
  45. if (time >= 100)    {
  46.   removeEventListener(Event.ENTER_FRAME,onFrame);
  47.   b = false;
  48. }
  49. drawCircle(ball_mc.x,ball_mc.y);
  50. xArr.push(ball_mc.x);
  51. yArr.push(ball_mc.y);
  52. ind = xArr.length;
  53. }
  54. function drawCircle(xx:Number,yy:Number)   {
  55. drawSp.graphics.beginFill(0×000000);
  56. drawSp.graphics.drawCircle(xx,yy,1);
  57. }
  58. reset_btn.addEventListener(MouseEvent.CLICK,reset);
  59. function reset(e)   {
  60. xball_mc.x = ball_mc.x = oldX;
  61. yball_mc.y = ball_mc.y = oldY;
  62. removeEventListener(Event.ENTER_FRAME,onFrame);
  63. }
  64. prev_btn.addEventListener(MouseEvent.CLICK,prev);
  65. function prev(e)   {
  66. if (! b)    {
  67.   ind > 5 ? ind -=  5:ind = 0;
  68.   xball_mc.x = ball_mc.x = xArr[ind];
  69.   yball_mc.y = ball_mc.y = yArr[ind];
  70. }
  71. }
  72. next_btn.addEventListener(MouseEvent.CLICK,nextF);
  73. function nextF(e)   {
  74. if (! b)    {
  75.   ind < xArr.length – 6 ? ind +=  5:ind = xArr.length – 1;
  76.   xball_mc.x = ball_mc.x = xArr[ind];
  77.   yball_mc.y = ball_mc.y = yArr[ind];
  78. }
  79. }
  80. clear_btn.addEventListener(MouseEvent.CLICK,clearFunc);
  81. function clearFunc(e)   {
  82. drawSp.graphics.clear();
  83. }

  84. visible_btn.addEventListener(MouseEvent.CLICK,visibleFunc);
  85. function visibleFunc(e)   {
  86. xball_mc.visible = ! xball_mc.visible;
  87. yball_mc.visible = ! yball_mc.visible;
  88. (visi=!visi) ? visible_btn.alpha =1:visible_btn.alpha = 0.5;
  89. }
复制代码
(, 下载次数: 15)




欢迎光临 应用思考-教育技术论坛 (http://etthink.com/) Powered by Discuz! X3.4