_x = 275;
_y = 100;
linestyle(8, 0xff0000);
lineTo(0, 1);
//画个固定点
g = 5;
//重力加速度
createEmptyMovieClip("bq", 0);
var r = 35;
//摆球的半径
bq.linestyle(r, 0x660099);
bq.lineTo(0, 1);
//画摆球
i = 0;
j = 0;
l = 250;
//l为摆长
a = 0.03;
//空气阻力
bq._y = l;
createEmptyMovieClip("bx", -1);
bx.linestyle(2);
bx.lineTo(bq._x, bq._y);
st = true;
function bd() {
var d2 = bq._x*bq._x+bq._y*bq._y;
if (st) {
if (d2>=l*l*0.99) {
v2 = 0;
j += 0.1;
i += v;
v += g/500*Math.sin(-i);
bq._x = l*Math.sin(i*Math.pow(1-a, j));
bq._y = l*Math.cos(i*Math.pow(1-a, j));
createEmptyMovieClip("bx", -1);
bx.linestyle(2);
// 画摆线;
bx.lineTo(bq._x, bq._y);
} else {
v2 += g/5;
bq._y += v2;
var y = Math.sqrt(l*l-bq._x*bq._x);
i = Math.atan2(bq._x, y);
if (bq._x<=0) {
v = v2/200;
} else {
v = -v2/200;
}
createEmptyMovieClip("bx", -1);
bx.linestyle(2);
bx.curveTo(bq._x/2, bq._y+l-Math.sqrt(d2), bq._x, bq._y);
}
}
}
//编写单摆运动的函数,包括了作自由落体运动与摆动
setInterval(bd, 20);
//执行函数
bq.onPress = function() {
this.onEnterFrame = function() {
var d = _xmouse*_xmouse+_ymouse*_ymouse;
if (d<=(l+r)*(l+r)) {
//如果鼠标与固定点的距离小于线长,则可以拖动摆球
startDrag(this);
st = false;
createEmptyMovieClip("bx", -1);
bx.linestyle(2);
bx.curveTo(bq._x/2, bq._y+l-Math.sqrt(d), bq._x, bq._y);
} else {
//否则小球离开鼠标开始运动
stopDrag();
st = true;
//判断开始运动的布尔值
i = Math.atan2(bq._x, bq._y);
//摆球偏离的角度
v = 0;
j = 0;
delete this.onEnterFrame;
}
};
};
//以上的函数使摆球在指定范围内可以拖动
bq.onRelease = function() {
stopDrag();
i = Math.atan2(bq._x, bq._y);
j = 0;
v = 0;
st = true;
delete this.onEnterFrame;
};
//放开鼠标则摆球开始运动
bq.onReleaseOutside = function() {
stopDrag();
i = Math.atan2(bq._x, bq._y);
j = 0;
st = true;
delete this.onEnterFrame;
};
//防止鼠标滑出摆外不能运动的现象
Flash 动画:
_y = 100;
linestyle(8, 0xff0000);
lineTo(0, 1);
//画个固定点
g = 5;
//重力加速度
createEmptyMovieClip("bq", 0);
var r = 35;
//摆球的半径
bq.linestyle(r, 0x660099);
bq.lineTo(0, 1);
//画摆球
i = 0;
j = 0;
l = 250;
//l为摆长
a = 0.03;
//空气阻力
bq._y = l;
createEmptyMovieClip("bx", -1);
bx.linestyle(2);
bx.lineTo(bq._x, bq._y);
st = true;
function bd() {
var d2 = bq._x*bq._x+bq._y*bq._y;
if (st) {
if (d2>=l*l*0.99) {
v2 = 0;
j += 0.1;
i += v;
v += g/500*Math.sin(-i);
bq._x = l*Math.sin(i*Math.pow(1-a, j));
bq._y = l*Math.cos(i*Math.pow(1-a, j));
createEmptyMovieClip("bx", -1);
bx.linestyle(2);
// 画摆线;
bx.lineTo(bq._x, bq._y);
} else {
v2 += g/5;
bq._y += v2;
var y = Math.sqrt(l*l-bq._x*bq._x);
i = Math.atan2(bq._x, y);
if (bq._x<=0) {
v = v2/200;
} else {
v = -v2/200;
}
createEmptyMovieClip("bx", -1);
bx.linestyle(2);
bx.curveTo(bq._x/2, bq._y+l-Math.sqrt(d2), bq._x, bq._y);
}
}
}
//编写单摆运动的函数,包括了作自由落体运动与摆动
setInterval(bd, 20);
//执行函数
bq.onPress = function() {
this.onEnterFrame = function() {
var d = _xmouse*_xmouse+_ymouse*_ymouse;
if (d<=(l+r)*(l+r)) {
//如果鼠标与固定点的距离小于线长,则可以拖动摆球
startDrag(this);
st = false;
createEmptyMovieClip("bx", -1);
bx.linestyle(2);
bx.curveTo(bq._x/2, bq._y+l-Math.sqrt(d), bq._x, bq._y);
} else {
//否则小球离开鼠标开始运动
stopDrag();
st = true;
//判断开始运动的布尔值
i = Math.atan2(bq._x, bq._y);
//摆球偏离的角度
v = 0;
j = 0;
delete this.onEnterFrame;
}
};
};
//以上的函数使摆球在指定范围内可以拖动
bq.onRelease = function() {
stopDrag();
i = Math.atan2(bq._x, bq._y);
j = 0;
v = 0;
st = true;
delete this.onEnterFrame;
};
//放开鼠标则摆球开始运动
bq.onReleaseOutside = function() {
stopDrag();
i = Math.atan2(bq._x, bq._y);
j = 0;
st = true;
delete this.onEnterFrame;
};
//防止鼠标滑出摆外不能运动的现象
Flash 动画:
回复Comments
作者:
{commentrecontent}