Back to "flash Basic Theory Class-Catalog"
Practical formula
In the book, we already have a variety of motion and effect formulas. I've extracted the most useful and commonly used formulas, equations, and snippets of code, and listed them at the end of this chapter. I think it would be very helpful to put them in the same place, so I put these things that I think most needed together as a reference for the whole. I will be on this page to write a letter.
Chapter III
Calculation of the underlying trigonometric function:
Sine value of angle = pair edge/Bevel
Cosine of angle = adjacent edge/hypotenuse
Tangent of angle = to edge/adjacent edge
Radians convert to angle and angle to radians:
radians = angle * math.pi/180
Angle = radians * 180/MATH.PI
Rotate to the mouse (or to any point):
// 用要旋转到的 x, y 坐标替换 mouseX, mouseY
dx = mouseX - sprite.x;
dy = mouseY - sprite.y;
sprite.rotation = Math.atan2(dy, dx) * 180 / Math.PI;
To create a waveform:
// 将x, y 或其它属性赋值给Sprite 影片或影片剪辑,
// 作为绘图坐标,等等。
public function onEnterFrame(event:Event){
value = center + Math.sin(angle) * range;
angle += speed;
}
To create a circle:
// 将x, y 或其它属性赋值给Sprite 影片或影片剪辑,
// 作为绘图坐标,等等。
public function onEnterFrame(event:Event){
xposition = centerX + Math.cos(angle) * radius;
yposition = centerY + Math.sin(angle) * radius;
angle += speed;
}
To create an ellipse:
// 将x, y 或其它属性赋值给Sprite 影片或影片剪辑,
// 作为绘图坐标,等等。
public function onEnterFrame(event:Event){
xposition = centerX + Math.cos(angle) * radiusX;
yposition = centerY + Math.sin(angle) * radiusY;
angle += speed;
}
Get the distance between two points:
// x1, y1 和 x2, y2 是两个点
// 也可以是 Sprite / MovieClip 坐标,鼠标坐标,等等。
dx = x2 – x1;
dy = y2 – y1;
dist = Math.sqrt(dx*dx + dy*dy);