几个有用的数学公式 for ActionScript 3

    技术2024-12-21  7

    1.Distance Between Two Points 两点间的距离

    dx = x2 – x1; dy = y2 – y1; dist = Math.sqrt(dx*dx + dy*dy);

    2. Inching Formulas 缓动公式

    sprite.x += (targetX - sprite.x) * easing;//easing: inching coefficient sprite.y += (targetY - sprite.y) * easing;

    3. Elastic Formulas 弹性公式

    vx += (targetX - sprite.x) * spring; //spring: elastic coefficient vy += (targetY - sprite.y) * spring; sprite.x += (vx *= friction); //friction: friction force sprite.y += (vy *= friction);

    4. Flexible Partial Shifts Formulas 柔性物体变换公式

    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;

    5. Rotation With Mouse Formulas 跟随鼠标转动

    dx = mouseX - sprite.x; dy = mouseY - sprite.y; sprite.rotation = Math.atan2(dy, dx) * 180 / Math.PI;

    6. Waveform Formulas 波形公式

    public function onEnterFrame1(event:Event):void { ball.y=centerScale+Math.sin(angle)*range; angle+=speed; }

    7. Heartthrob Formulas 心跳公式

    public function onEnterFrame1(event:Event):void { ball.scaleX=centerScale+Math.sin(angle)*range; ball.scaleY=centerScale+Math.sin(angle)*range; angle+=speed; }

    8. Circle Rotation Formulas 公转公式

    public function onEnterFrame(event:Event):void { ball.x=centerX+Math.cos(angle)*radius; ball.y=centerY+Math.sin(angle)*radius; angle+=speed; }

    9. Get Circle Area 获取圆周区域

    public function getArea():Number { // The formula is Pi times the radius squared. return Math.PI * Math.pow((width / 2), 2); }

    10. Get Circumference Ratio 获取圆周长度

    public function getCircumference():Number { // The formula is Pi times the diameter. return Math.PI * width; }

    11. Elliptic Rotation Formulas 椭圆公转

    public function onEnterFrame(event:Event):void { ball.x=centerX+Math.cos(angle)*radiusX; ball.y=centerY+Math.sin(angle)*radiusY; angle+=speed; }

    12. Color operations 颜色操作,获取alpha值

    var t:uint=0×77ff8877; var s:uint=0xff000000; var h:uint=t&s; var m:uint=h>>24; trace(m);

    13. Hex to Decimal 16进制转10进制

    trace(hexValue);

    14. Decimal to Hex 10进制转16进制

    decimalValue.toString(16);

    15. Pick Up Color 颜色拾取

    red = color24 >> 16; green = color24 >> 8 & 0xFF; blue = color24 & 0xFF; alpha = color32 >> 24; red = color32 >> 16 & 0xFF; green = color32 >> 8 & 0xFF; blue = color232 & 0xFF;

    16. Color Bit Arithmetic 颜色位运算

    color24 = red << 16 | green << 8 | blue; color32 = alpha << 24 | red << 16 | green << 8 | blue;

    from:16 Useful Mathematical Formulas In ActionScript 3

    最新回复(0)