flash as3.0实用公式

更新时间:15-09-16 19:00 热度:486
 
 基础三角学函数的计算:角的正弦值 = 对边 / 斜边角的余弦值 = 邻边 / 斜边角的正切值 = 对边 / 邻边 弧度改换为角度以及角度改换为弧度:弧度 = 角度 * math.pi / 180角度 = 弧度 * 180 / math.pi 向鼠标(还是不论什么一个点)旋转:// 用要旋转到的 x, y 坐标调换 mousex, mouseydx = mousex - sprite.x;dy = mousey - sprite.y;sprite.rotation = math.atan2(dy, dx) * 180 / math.pi; 开创波形:// 将 x, y 或其他属性赋值给 sprite 影片儿或影片儿剪接,// 作为绘图坐标,等等。public function onenterframe(event:event){  value = center + math.sin(angle) * range;  angle += speed;} 开创圆形:// 将 x, y 或其他属性赋值给 sprite 影片儿或影片儿剪接,// 作为绘图坐标,等等。public function onenterframe(event:event){  xposition = centerx + math.cos(angle) * radius;  yposition = centery + math.sin(angle) * radius;  angle += speed;} 开创鸭子蛋圆:// 将 x, y 或其他属性赋值给 sprite 影片儿或影片儿剪接,// 作为绘图坐标,等等。public function onenterframe(event:event){  xposition = centerx + math.cos(angle) * radiusx;  yposition = centery + math.sin(angle) * radiusy;  angle += speed;} 取得两点间的距离:// x1, y1 和 x2, y2 是两个点// 也可以是 sprite / movieclip 坐标,鼠标坐标,等等。dx = x2 – x1;dy = y2 – y1;dist = math.sqrt(dx*dx + dy*dy);  十六进制改换为逢十进位:trace(hexvalue); 逢十进位改换为十六进制:trace(decimalvalue.tostring(16));颜色组合:color24 = red << 16  green << 8  blue;color32 = alpha << 24  red << 16  green << 8  blue; 颜色提出取得:red = color24 >> 16;green = color24 >> 8 & 0xff;blue = color24 & 0xff;alpha = color32 >> 24;red = color32 >> 16 & 0xff;green = color32 >> 8 & 0xff;blue = color232 & 0xff; 越过某点画出曲线:// xt, yt 是我们想要越过的一点儿// x0, y0 以及 x2, y2 是曲线的两端x1 = xt * 2 – (x0 + x2) / 2;y1 = yt * 2 – (y0 + y2) / 2;moveto(x0, y0);curveto(x1, y1, x2, y2);角速度改换为 x, y 速度:vx = speed * math.cos(angle);vy = speed * math.sin(angle); 角加速度(效用于物体上的 force)改换为 x, y 加速度:ax = force * math.cos(angle);ay = force * math.sin(angle); 将加速度参加速度:vx += ax;vy += ay; 将速度参加坐标:movieclip._x += vx;sprite.y += vy;移除出界对象: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){  // 删去影片儿的代码} 重置出界对象: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){  // 重置影片儿的位置和速度}荧幕围绕出界对象: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 = bottom + sprite.height / 2;}磨擦力应用(准确办法)   :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;磨擦力应用(简单方便办法)vx *= friction;vy *= friction;简单缓动运动,长形:var dx:number = targetx - sprite.x;var dy:number = targety - sprite.y;vx = dx * easing;vy = dy * easing;sprite.x += vx;sprite.y += vy; 简单缓动运动,中形:vx = (targetx - sprite.x) * easing;vy = (targety - sprite.y) * easing;sprite.x += vx;sprite.y += vy; 简单缓动运动,短形:sprite.x += (targetx - sprite.x) * easing;sprite.y += (targety - sprite.y) * easing;简单弹性运动,长形: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; 简单弹性运动,中形:vx += (targetx - sprite.x) * spring;vy += (targety - sprite.y) * spring;vx *= friction;vy *= friction;sprite.x += vx;sprite.y += vy; 简单弹性运动,短形:vx += (targetx - sprite.x) * spring;vy += (targety - sprite.y) * spring;sprite.x += (vx *= friction);sprite.y += (vy *= friction);偏移弹性运动: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;// 如先例弹性运动到 targetx, targety 距离碰撞检验测定:// 从事电影事业片儿 spritea 和 spriteb 着手// 假如运用一个空白影片儿,或影片儿没有半径(radius)属性// 可以用宽度或高度除以 2。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){  // 处置碰撞} 多物体碰撞检验测定:var numobjects:uint = 10;for(var i:uint = 0; i < numobjects - 1; i++){  // 运用变量 i 提出取得援用  var objecta = objects[i];  for(var j:uint = i+1; j  {    // // 运用变量 j 提出取得援用    var objectb = objects[j];    // perform collision detection    // between objecta and objectb  }}坐标旋转:x1 = math.cos(angle) * x - math.sin(angle) * y;y1 = math.cos(angle) * y + math.sin(angle) * x; 反坐标旋转:x1 = math.cos(angle) * x + math.sin(angle) * ;yy1 = math.cos(angle) * y - math.sin(angle) * x;动量守恒的算术表现式:                      (m0 – m1) * v0 + 2 * m1 * v1v0final = ----------------------------------------------                                     m0 + m1                      (m1 – m0) * v1 + 2 * m0 * v0v1final = ---------------------------------------------                                     m0 + m1 动量守恒的 actionscript 表现式,短形:var vxtotal:number = vx0 - vx1;vx0 = ((ball0.mass - ball1.mass) * vx0 +2 * ball1.mass * vx1) /(ball0.mass + ball1.mass);vx1 = vxtotal + vx0;万有引力的普通公式:force = g * m1 * m2 / distance2actionscript 成功实现万有万有引力:function gravitate(parta:ball, partb:ball):void{  var dx:number = 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;}余弦定理a2 = b2 + c2 - 2 * b * c * cos ab2 = a2 + c2 - 2 * a * c * cos bc2 = a2 + b2 - 2 * a * b * cos c actionscript 的余弦定理: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));基本透视法:scale = fl / (fl + zpos);sprite.scalex = sprite.scaley = scale;sprite.alpha = scale; // 可选sprite.x = vanishingpointx + xpos * scale;sprite.y = vanishingpointy + ypos * scale; z 排序:// 如果有一个带有 zpos 属性的 3d 物体的数组objectarray.sorton("zpos", array.descending  array.numeric);for(var i:uint = 0; i < numobjects; i++){  setchildindex(objectarray[i], i);}坐标旋转:x1 = cos(anglez) * xpos - sin(anglez) * 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 距离:     dist = math.sqrt(dx * dx + dy * dy + dz * dz);