5.26.2010

[AS3] "動畫"基本數學公式整理

Flash Actionscript 3.0動畫製作所需要的基本數學公式:

基本三角函數的計算:

角的正弦值(Sine) = 對邊 / 斜邊

角的餘弦值(Cosine) = 鄰邊 / 斜邊

角的正切值(Tangent) = 對邊 / 鄰邊

角度制與弧度制的相互轉換:

弧度 = 角度 * Math.PI / 180

角度 = 弧度 * 180 / Math.PI

計算兩點間距離:

dx = x2 – x1;

dy = y2 – y1;

dist = Math.sqrt(dx*dx + dy*dy);

緩動公式:

sprite.x += (targetX – sprite.x) * easing;//easing為緩動係數變數

sprite.y += (targetY – sprite.y) * easing;

彈性公式:

vx += (targetX – sprite.x) * spring;//spring為彈性係數

vy += (targetY – sprite.y) * spring;

sprite.x += (vx *= friction);//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;

向滑鼠旋轉(如撥時鐘效果等)

dx = mouseX – sprite.x;

dy = mouseY – sprite.y;

sprite.rotation = Math.atan2(dy, dx) * 180 / Math.PI;

波形運動:

public function onEnterFrame1(event:Event):void {

ball.y=centerScale+Math.sin(angle)*range;

angle+=speed; }

心跳:

public function onEnterFrame1(event:Event):void {

ball.scaleX=centerScale+Math.sin(angle)*range;

ball.scaleY=centerScale+Math.sin(angle)*range;

angle+=speed; }

圓心旋轉:

public function onEnterFrame(event:Event):void {

ball.x=centerX+Math.cos(angle)*radius;

ball.y=centerY+Math.sin(angle)*radius;

angle+=speed; }

橢圓旋轉:

public function onEnterFrame(event:Event):void {

ball.x=centerX+Math.cos(angle)*radiusX;

ball.y=centerY+Math.sin(angle)*radiusY;

angle+=speed; }

顏色運算得到透明值:

var t:uint=0×77ff8877

var s:uint=0xff000000

var h:uint=t&s

var m:uint=h>>>24

trace(m)

轉換為十進位:

trace(hexValue);

十進位轉換為十六進位:

decimalValue.toString(16)

顏色提取:

red = color24 >> 16;

green = color24 >> 8 & 0xFF;

blue = color24 & 0xFF;

alpha = color32 >> 24;

red = color32 >> 16 & 0xFF;

green = color32 >> 8 & 0xFF;

blue = color232 & 0xFF;

按位計算得到顏色值:

color24 = red <<>

color32 = alpha <<>

沒有留言:

張貼留言