As advanced trigonometric functions and applications

Source: Internet
Author: User
Tags cos sin

In the AS 03 tutorial, we introduced basic applications of trigonometric functions.
Supplement and develop the content of the previous course
Review the method of circle painting: x coordinate cos (n), y coordinate sin (n); n
From 0 ~ Radians of 360

1. Draw an ellipse
For comparison, we just want to draw the circle method R
, Split into two parts.
Divided into W and H
Respectively control the width and height of the ellipse.
_ Root. createEmptyMovieClip ("MC ",
1 );

MC. _ x = 200;

MC. _ y =
200;
// Create an empty video clip and place it in the center of the stage as a draw line container


Var W = 50;

Var H = 30;
// Elliptical width: W, elliptical height: H.

MC. moveTo (W * Math. cos (0), H * Math. sin (0 ));
// Set the starting point of the draw line

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

}
// When W = H, the circle is drawn.



II. Elliptical distribution
   
In learning
03 in the tutorial, we introduced the method of multi-edge layout. With this foundation, the production of this instance is just a piece of cake. ^_^

Instance 1:

Step 1:

   
Draw a star, save it as a video clip, connect to it, and choose export from the shortcut menu. The logo is "star"
Step 2:
Add the AS code:
_ Root. createEmptyMovieClip ("MC", 1 );

MC. _ x = 200;

MC. _ y = 200;

Var Num = 22;
// Number of stars

Var W = 200;

Var H =
100;
// Elliptical width: W, elliptical height: H; positive circle when W = H

Var angle =
(360 * Math. PI/180)/Num;
// Equal to each other =
Radian of a circle (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 );
}
// Copy num to scatter evenly to the circle with ang as the distance


Instance 2:

Step 1:
   
Draw a star, save it as a video clip, connect to it, and choose export from the shortcut menu. The logo is "star"
Step 2:
Add the AS code:
Var num = 22;
// Number of stars
Var W = 60;

Var H = 30;
// Width and height of the ellipse
Var
Wdir = 1;

Var hdir = 1;
// Wdir: orientation to width
// Hdir: in the high direction
_ Root. createEmptyMovieClip ("MC", 1 );

MC. _ x = Stage. width/2;

MC. _ y = Stage. height/2;
// The center of the center X and Y coordinates are the center of the stage

Var angle =
(360 * Math. PI/180)/num;
// Equal to each other =
Radian of a circle (360 * PI/180)/num
For (I = 0; I <num; I ++ ){

MC. attachMovie ("star", "star" + I, I );

}
// Copy the stars for backup
Var
Right = Stage. width/2-20;

Var left = 20;

Var bottom = Stage. height/2-20;

Var top = 20;
// Set the widest and narrower values of the circle: wmax and wmin. Set the highest and shortest values of the circle: hmax and hmin.


_ Root. onEnterFrame
= Function (){

For (I = 0; I <num; I ++ ){

MC ["star" + I]. _ x =
W * Math. cos (I * angle );

MC ["star" + I]. _ y =
H * Math. sin (I * angle );

MC ["star" + I]. _ rotation + =
30;

}
// The Circle size W and H are dynamically changed.


W + = wdir * 5;

H + = hdir * 5;
// Changing W and H
If
(W> right | W <left ){

Wdir * =-1;

}

If (H> bottom | H <top ){

Hdir * =-1;

}
// These two sections are used to determine the backward direction of movement


};



III. Sin text string

Step 1:
   
Drag a dynamic text box named txt and save it as a video clip.
   
Right-click the MC file in the library-> link-> Select "as ActionScript"
Export "and" export in the first frame ". The" identifier "is" ST ".

Step 2:
Add the AS code:
Var mytext: String =
"Learning the sea is a boat ";

Var angle = 180/mytext. length;
// Sine image (180 degrees) degree of each part based on the number of words


For (I = 0;
I <mytext. length; I ++ ){

Var p: MovieClip = _ root. attachMovie ("ST", "ST" + I,
I );

P.txt =
Mytext. charAt (I );
// Extract characters one by one

P. _ x = 50 + 65 * I;

P. _ y = 60;
// Initial position of the video


P. angle =
Angle * I;
// Define attributes to indicate the initial angle


P. onEnterFrame = function (){

This. A =
(This. angle) * Math. PI/180;

// Converts degrees to radians.

This. _ xscale =
This. _ yscale = 100 + 50 * Math. sin (this. );

// Adjust the video size from the sine angle. The value ranges from 50 to 50 ~ 150]

This. angle + = 10;

};

}

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.