学习Math与 setInterval的使用,呵呵 顺便复习了一下初中数学与物理。公开源码如下:
//检测鼠标速度
var pre_x = _xmouse;
var pre_y = _ymouse;
var mouseSpeed = 0;
var mouse_angle = 0;
//检测鼠标开始
function caculateMouseSpeed() {
var tempX = Math.pow(_xmouse-pre_x, 2);
var tempY = Math.pow(_ymouse-pre_y, 2);
var dist = Math.sqrt(tempX+tempY);
//角度计算开始
var y_mouse = Math.abs(_ymouse-pre_y);
var x_mouse = Math.abs(_xmouse-pre_x);
if (_ymouse>pre_y) {
if (_xmouse>pre_x) {
mouse_angle = Math.acos(x_mouse/dist)*180/Math.PI+90;
}
if (_xmouse == pre_x) {
mouse_angle = 180;
}
if (_xmouse<pre_x) {
mouse_angle = -(Math.atan(y_mouse/x_mouse)*180/Math.PI+90);
}
}
if (_ymouse<pre_y) {
if (_xmouse>pre_x) {
mouse_angle = Math.asin(x_mouse/dist)*180/Math.PI;
}
if (_xmouse == pre_x) {
mouse_angle = 0;
}
if (_xmouse<pre_x) {
mouse_angle = -(Math.atan(x_mouse/y_mouse)*180/Math.PI);
}
}
if (_ymouse == pre_y) {
if (_xmouse>pre_x) {
mouse_angle = 90;
}
if (_xmouse == pre_x) {
mouse_angle = 0;
}
if (_xmouse<pre_x) {
mouse_angle = -90;
}
}
mo._rotation = mouse_angle;
trace(mouse_angle);
//角度计算结束
mouseSpeed = dist/5;
if (mouseSpeed>=300) {
//最高限速
mouseSpeed = 300;
}
mo._yscale=mouseSpeed;
pre_x = _xmouse;
pre_y = _ymouse;
}
setInterval(caculateMouseSpeed, 100);
var pre_x = _xmouse;
var pre_y = _ymouse;
var mouseSpeed = 0;
var mouse_angle = 0;
//检测鼠标开始
function caculateMouseSpeed() {
var tempX = Math.pow(_xmouse-pre_x, 2);
var tempY = Math.pow(_ymouse-pre_y, 2);
var dist = Math.sqrt(tempX+tempY);
//角度计算开始
var y_mouse = Math.abs(_ymouse-pre_y);
var x_mouse = Math.abs(_xmouse-pre_x);
if (_ymouse>pre_y) {
if (_xmouse>pre_x) {
mouse_angle = Math.acos(x_mouse/dist)*180/Math.PI+90;
}
if (_xmouse == pre_x) {
mouse_angle = 180;
}
if (_xmouse<pre_x) {
mouse_angle = -(Math.atan(y_mouse/x_mouse)*180/Math.PI+90);
}
}
if (_ymouse<pre_y) {
if (_xmouse>pre_x) {
mouse_angle = Math.asin(x_mouse/dist)*180/Math.PI;
}
if (_xmouse == pre_x) {
mouse_angle = 0;
}
if (_xmouse<pre_x) {
mouse_angle = -(Math.atan(x_mouse/y_mouse)*180/Math.PI);
}
}
if (_ymouse == pre_y) {
if (_xmouse>pre_x) {
mouse_angle = 90;
}
if (_xmouse == pre_x) {
mouse_angle = 0;
}
if (_xmouse<pre_x) {
mouse_angle = -90;
}
}
mo._rotation = mouse_angle;
trace(mouse_angle);
//角度计算结束
mouseSpeed = dist/5;
if (mouseSpeed>=300) {
//最高限速
mouseSpeed = 300;
}
mo._yscale=mouseSpeed;
pre_x = _xmouse;
pre_y = _ymouse;
}
setInterval(caculateMouseSpeed, 100);
最近在研究的一个Flash,众志成城
CSS2定义xml文档样式




