Important Formulas in This Chapter

Look at this. You have a brand-new shiny toolbox, and already you have more than a half dozen tools to put in it. The full set of tools will also appear Chapter 19, but lets look at what youve added so far.

Calculate basic trigonometric functions:

 sine of angle = opposite / hypotenuse cosine of angle = adjacent / hypotenuse tangent of angle = opposite / adjacent 

Convert radians to degrees and degrees to radians:

 radians = degrees * Math.PI / 180 degrees = radians * 180 / Math.PI 

Rotate to the mouse (or any point):

 // substitute _xmouse, _ymouse with the x, y point to rotate to var dx = _xmouse - movieclip._x; var dy = _ymouse - movieclip._y; movieclip._rotation = Math.atan2(dy, dx) * 180 / Math.PI; 

Create waves:

 // assign value to _x, _y or other property of movie clip, // use as drawing coordinates, etc. // note: angle does not have to be zero, // but must be defined as something prior to adding speed angle = 0; onEnterFrame = function(){    value = center + Math.sin(angle) * range;    angle += speed; } 

Create circles:

 // assign position to _x and _y of movie clip, // use as drawing coordinates, etc. onEnterFrame = function(){    xposition = centerX + Math.cos(angle) * radius;    yposition = centerY + Math.sin(angle) * radius;    angle += speed; } 

Create ovals:

 // assign position to _x and _y of movie clip, // use as drawing coordinates, etc. onEnterFrame = function(){    xposition = centerX + Math.cos(angle) * radiusX;    yposition = centerY + Math.sin(angle) * radiusY;    angle += speed; } 

Get the distance between two points:

 // points are x1,y1 and x2,y2 // can be movie clip positions, mouse coordinates, etc. dx = x2  x1; dy = y2  y1; dist = Math.sqrt(dx*dx + dy*dy); 

Of course, if I just wanted to publish a list of formulas, I could have saved myself a lot of time and done just that. So look these over and make sure you fully understand how each one works. If you have any questions, go back to the point in the chapter where it was introduced, experiment with it, and research it more if you need to, until you can really think with the concept.



Foundation ActionScript. Animation. Making Things Move
Foundation Actionscript 3.0 Animation: Making Things Move!
ISBN: 1590597915
EAN: 2147483647
Year: 2005
Pages: 137
Authors: Keith Peters

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net