Flash as3.0 Practical formula

Source: Internet
Author: User
Tags acos cos reset sin
 Calculation of the basic trigonometric function: the sine value of the angle = the cosine of the edge/oblique corner = The tangent of the adjacent/oblique corners = The conversion of the edge/adjacent edge to the angle and the angle to radians: radians = angle * math.pi/180 angle = radians * 180/m Ath.
PI rotates to the mouse (or any point)://Replaces MouseX with the x, Y coordinate to be rotated to, mousey dx = mousex-sprite.x;
dy = mousey-sprite.y;
 
Sprite.rotation = math.atan2 (dy, dx) * 180/MATH.PI;
Create waveform://assign X, Y, or other properties to Sprite movie or movie clips,//as drawing coordinates, and so on.
  Public Function Onenterframe (event:event) {value = center + math.sin (angle) * range;
Angle + = speed;
Create a circle://assign X, Y, or other properties to Sprite movie or movie clips,//as drawing coordinates, and so on.
  Public Function Onenterframe (event:event) {xposition = CenterX + math.cos (angle) * RADIUS;
  YPosition = centery + math.sin (angle) * RADIUS;
Angle + = speed;
Create ellipse://assign X, Y, or other properties to Sprite movie or movie clips,//as drawing coordinates, and so on.
  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 and x2, y2 is two dots//can also be sprite/movieclip coordinates, mouse coordinates, and so on.
DX = x2–x1;
dy = y2–y1; Dist =MATH.SQRT (DX*DX + dy*dy);
 
16 binary conversion to decimal: Trace (hexvalue);
Decimal conversion to 16 binary: Trace (decimalvalue.tostring (16)); Color combination: Color24 = Red << 16 | Green << 8 |
Blue Color32 = Alpha << 24 | Red << 16 | Green << 8 |
 
Blue
Color extraction: Red = Color24 >> 16;
Green = Color24 >> 8 & 0xFF;
Blue = Color24 & 0xFF;
Alpha = Color32 >> 24;
Red = Color32 >> & 0xFF;
Green = Color32 >> 8 & 0xFF;
 
Blue = color232 & 0xFF;
Draw curves through a point://XT, YT is a bit//x0, y0 and x2 we want to cross, Y2 is the ends of the curve x1 = XT * 2– (x0 + x2)/2;
Y1 = yt * 2– (y0 + y2)/2;
MoveTo (x0, y0);
Curveto (x1, y1, x2, y2);
Angular velocity converted to x, y speed: VX = speed * Math.Cos (angle);
 
VY = speed * Math.sin (angle);
Angular acceleration (force on an object) is converted to X, y acceleration: ax = force * MATH.COS (angle);
 
ay = force * Math.sin (angle);
Add acceleration to speed: VX + = ax;
 
Vy + = ay;
Add speed to coordinates: MOVIECLIP._X = VX;
Sprite.y + = VY; Remove an out of bounds object: if (Sprite.x-sprite.width/2 > Right | | sprite.x + SPRITE.WIDTH/2 < left | | sprite.y–sprite.heighT/2 > Bottom | | Sprite.y + SPRITE.HEIGHT/2 < top) {//delete movie code} reset out of Bounds object: if (Sprite.x-sprite.width/2 > Right | | sprite.x +
Sprite.width/2 < left | |
SPRITE.Y–SPRITE.HEIGHT/2 > Bottom | | Sprite.y + SPRITE.HEIGHT/2 < top) {//reset movie's position and speed} screen wraps around out of bounds object: if (Sprite.x-sprite.width/2 > right) {Sprite
. x = LEFT-SPRITE.WIDTH/2; else if (sprite.x + SPRITE.WIDTH/2 < left) {sprite.x = right + Sprite.width/2;} if (Sprite.y–sprite.height/ 2 > Bottom) {sprite.y = TOP–SPRITE.HEIGHT/2;} else if (Sprite.y + SPRITE.HEIGHT/2 < top) {sprite.y = bot
Tom + SPRITE.HEIGHT/2;
Friction application (correct method): Speed = MATH.SQRT (VX * vx + VY * vy);
Angle = math.atan2 (VY, VX);
if (Speed > friction) {speed = friction;} else {speed = 0;} VX = Math.Cos (angle) * speed;
VY = Math.sin (angle) * speed;
Friction application (simple method) VX *= friction;
VY *= Friction;
Simple slow motion, long shape: var dx:number = targetx-sprite.x;
var dy:number = targety-sprite.y;
VX = dx * easing; Vy = dy * easing;
Sprite.x + VX;
 
Sprite.y + = VY;
Simple slow motion, medium: VX = (targetx-sprite.x) * easing;
VY = (targety-sprite.y) * easing;
Sprite.x + VX;
 
Sprite.y + = VY;
Simple slow motion, short form: sprite.x + = (targetx-sprite.x) * easing;
Sprite.y + = (targety-sprite.y) * easing;
Simple elastic motion, long shape: var ax:number = (targetx-sprite.x) * SPRING;
var ay:number = (targety-sprite.y) * SPRING;
VX + ax;
Vy + = ay;
VX *= friction;
VY *= Friction;
Sprite.x + VX;
 
Sprite.y + = VY;
Simple elastic Motion, Medium: VX + + (targetx-sprite.x) * SPRING;
VY + = (targety-sprite.y) * SPRING;
VX *= friction;
VY *= Friction;
Sprite.x + VX;
 
Sprite.y + = VY;
Simple elastic motion, short form: VX + + (targetx-sprite.x) * SPRING;
VY + = (targety-sprite.y) * SPRING;
Sprite.x + = (VX *= friction);
Sprite.y + = (vy *= friction);
Offset elastic motion: var dx:number = Sprite.x-fixedx;
var dy:number = Sprite.y-fixedy;
var angle:number = math.atan2 (dy, dx);
var targetx:number = Fixedx + math.cos (angle) * SPRINGLENGTH;
var targety:number = Fixedx + math.sin (angle) * SPRINGLENGTH; Like the preceding example elasticityMotion to Targetx, targety distance Collision Detection://Starting from film Spritea and SPRITEB//If using a blank movie, or the movie has no radius (RADIUS) attribute//Can be divided by 2 with width or height.
var dx:number = spriteb.x-spritea.x;
var dy:number = spriteb.y-spritea.y;
var dist:number = math.sqrt (dx * dx + dy * dy);
if (Dist < Spritea.radius + Spriteb.radius) {//handling collisions} Multiple object Collision detection: var numobjects:uint = 10;
  for (var i:uint = 0; i < numObjects-1; i++) {//Use variable I to extract references to var objecta = objects[i];
    for (var j:uint = i+1 J {/////Use variable J to extract reference var OBJECTB = objects[j];  Perform collision detection//between OBJECTA and OBJECTB} coordinate rotation: x1 = math.cos (angle) * X-math.sin (angle) *
Y
 
Y1 = Math.Cos (angle) * y + math.sin (angle) * x;
Anti-coordinate rotation: x1 = math.cos (angle) * x + math.sin (angle) *; y y1 = math.cos (angle) * Y-math.sin (angle) * x;
                                     Mathematical expressions of Momentum Conservation: (M0–M1) * V0 + 2 * M1 * v1 v0final =---------------------------------------------- M0 + m1 (M1–M0) * v1 + 2 * m0 * V0 v1final =---------------------------------------------M0 + M1 Momentum conservation Action
Script expression, short form: var vxtotal:number = vx0-vx1;
vx0 = ((ball0.mass-ball1.mass) * vx0 + 2 * ball1.mass * vx1)/(Ball0.mass + ball1.mass);
VX1 = Vxtotal + vx0; General formula of gravitation: force = G * M1 * M2/distance2 ActionScript to achieve gravitation: function gravitate (Parta:ball, partb:ball): void {var dx:n
  Umber = partb.x-parta.x;
  var dy:number = partb.y-parta.y;
  var distsq:number = dx * dx + dy * dy;
  var dist:number = math.sqrt (DISTSQ);
  var force:number = Parta.mass * PARTB.MASS/DISTSQ;
  var ax:number = Force * dx/dist;
  var ay:number = Force * dy/dist;
  PARTA.VX + = Ax/parta.mass;
  Parta.vy + = Ay/parta.mass;
  PARTB.VX-= Ax/partb.mass;
Partb.vy-= Ay/partb.mass; The cosine theorem a2 = b2 + c2-2 * b * c * cos A b2 = a2 + c2-2 * A * c * cos b c2 = a2 + b2-2 * A * b * cos c ActionScript
Cosine theorem: A = Math.acos ((b * b + c * c-a * A)/(2 * b * c)); B = Math.acos (A* A + c * C-b * b)/(2 * A * c));
c = Math.acos ((A * a + b * b-c * c)/(2 * A * b));
Basic Perspective Method: Scale = FL/fl + zpos;
Sprite.scalex = Sprite.scaley = scale; Sprite.alpha = scale;
Optional sprite.x = vanishingpointx + xpos * scale;
 
Sprite.y = vanishingpointy + ypos * scale; Z Sort://Suppose there is an array of 3D objects with the Zpos attribute Objectarray.sorton ("Zpos", array.descending |
Array.numeric); for (var i:uint = 0; i < numobjects; i++) {Setchildindex (objectarray[i], i);} coordinate rotation: x1 = cos (anglez) * Xpos-sin (an
Glez) * YPOS;
y1 = cos (anglez) * ypos + sin (anglez) * XPOS;
x1 = cos (angley) * Xpos-sin (Angley) * ZPOS;
Z1 = cos (angley) * zpos + sin (angley) * XPOS;
y1 = cos (anglex) * Ypos-sin (Anglex) * ZPOS;
 
Z1 = cos (anglex) * zpos + sin (anglex) * YPOS;
 3D Distance: dist = math.sqrt (dx * dx + dy * dy + dz * dz);

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.