Flash basic Theory Class 19th Chapter Practical Skill Ⅲ

Source: Internet
Author: User

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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.