在flash里用向量来制作运动模拟


向量负责用于计算力,绘图库负责把向量表示出来
下面是匀速圆周运动的例子
图片如下:


code
import Vector;
import fbook.graphics.pen.*;
import fbook.graphics.draw2d.*;
import fbook.graphics.draw2d.arrow.*;
import fbook.graphics.GDI;
var cur_mc = this;
//给球的即时速度,看受力图时可加大速度
var vel = new Vector(200, 500);
//速度向量的长度
var l=vel.getLength()
//位置向量
var pos = new Vector(move_mc._x, move_mc._y);
/***绘图****/
var _p1:IPen = new SolidPen(1, 0x000000, 100);
var _g:GDI = GDI.getInstance();
setInterval(this, "move", 30);
function move() {
  //绳子拉力
  var _lal = new Vector(move_mc._x-top_mc._x, move_mc._y-top_mc._y);
  //向量相加
  var f2 = vel.plusNew(_lal);
  _g.line(_p1, new SolidLineArrow(true, move_mc._x, move_mc._y, vel.x+move_mc._x, vel.y+move_mc._y));
  //半径
  var r = _lal.getLength();
  //相加后的长度
  var len = f2.getLength();
  //单位化
  f2.normal();
  //重新设置长度
  f2.scale(len-r);
  //改变方向后的速度
  vel.minus(f2);
  var len = vel.getLength();
  _g.target = this.createEmptyMovieClip("mc", 1);
  _g.line(_p1, new SolidLineArrow(true, top_mc._x, top_mc._y, _lal.x+top_mc._x, _lal.y+top_mc._y));
  _g.line(_p1, new SolidLineArrow(true, move_mc._x, move_mc._y, vel.x+move_mc._x, vel.y+move_mc._y));
  //_g.line(_p1, new SolidLineArrow(true, move_mc._x, move_mc._y, f3.x+move_mc._x, f3.y+move_mc._y));
  //_g.line(_p1, new SolidLineArrow(true, top_mc._x, top_mc._y, f.x+top_mc._x, f.y+top_mc._y));
  pos.plus(vel);
  
  move_mc._x = pos.x;
  move_mc._y = pos.y;
  //设置成原来的速度
  vel.normal()
  vel.setLength(l)
  
}
本文转自:http://www.5uflash.com/flashjiaocheng/Flashyingyongkaifa/883.html

你可能感兴趣的:(html,F#,Flash)