[As Functional code Tutorial 04] Advanced trigonometric Functions

Source: Internet
Author: User
Tags cos sin

In the As 03 tutorial, we introduced the basic application of trigonometric functions

Now to complement and develop the content of the last lesson

Review the Circle-drawing method: x-coordinate cos (n), y-coordinate sin (n); n the radian from the 0~360

First, draw the ellipse

By contrast, we're just dividing the circle by the way R, in Split.

Divided into W and H respectively control the width and height of the ellipse.

_root.createEmptyMovieClip("MC", 1);
MC._x = 200;
MC._y = 200;
//创建一个空影片剪辑,放在舞台中央作为画线容器
var W = 50;
var H = 30;
//椭圆宽:W,椭圆高:H.
MC.moveTo(W*Math.cos(0), H*Math.sin(0));
//设置画线起点
MC.lineStyle(2);
for (n=1; n < 360; n++) {
 tox = W*Math.cos(n*Math.PI/180);
 toy = H*Math.sin(n*Math.PI/180);
 MC.lineTo(tox, toy);
}
//当W=H的时候,画出的就是正圆。

Ii. the distribution of the ellipse

In the course of learning as 03 we introduced the multilateral style of painting, and with this foundation in the production of this example is a piece of cake. ^_^

Example 1:

Step 1:

Draw a star, Save as a movie clip, connect-> Export-> marker "star"

Step 2:

Add as code:

_root.createEmptyMovieClip("MC", 1);
MC._x = 200;
MC._y = 200;
var Num = 22;
//星星数量
var W = 200;
var H = 100;
//椭圆宽:W,椭圆高:H;当W=H时是正圆
var angle = (360*Math.PI/180)/Num;
//每等份 = 圆的弧度(360*PI/180)/num份
for (i=0; i < num; i++) {
 MC.attachMovie("star", "star"+i, i);
 MC["star"+i]._x = W*Math.cos(i*angle);
 MC["star"+i]._y = H*Math.sin(i*angle);
}
//复制num个以ang为距离平均分散到圆中

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.