zoukankan      html  css  js  c++  java
  • 转:实用公式 Useful Mathematical Formulas In ActionScript 3

    http://nwhy.org/16-useful-mathematical-formulas-in-actionscript-3.html

    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

    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

    trace(hexValue);

    14. Decimal to Hex

    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;

  • 相关阅读:
    谈谈我的经历--【产品设计中遇到的坑0】系列文章的序
    2017.02.04,读书,2017第二本《把时间当作朋友》读书笔记
    读书《重生,七年就是一辈子》
    好剧推荐:This is us
    直播预告:产品设计中不得不知的事情
    高德地图事件与插件绑定
    高德地图基础
    es6 Iterator和for...of循环
    class与class的继承
    JS保留两位小数的几种方法
  • 原文地址:https://www.cnblogs.com/xbglbc/p/2012678.html
Copyright © 2011-2022 走看看