Flash Animation その1

Flashの座標系

      • 左上が(x,y) = (0,0)
      • 角度は時計回り

Flash三角関数

Adobe - カスタマーサポートからのお知らせ

度とラジアン

度数をラジアンに変換
ラジアン = 度数*Math.PI/180

ラジアンを度数に変換
度数 = ラジアン*180/Math.PI

sinとcos

角度 θ で距離 D の位置座標は (D*cosθ, D*sinθ)

tanとatan

座標が (x, y) のとき、角度を θ すると
tanθ = y / x
三角関数の値から、逆に角度を返す関数
θ = atan(tanθ) = atan(y / x)

atanの使い方。座標から角度をもとめる。

onClipEvent (enterFrame) {

 var nMouseX = _root._xmouse-this._x;
 var nMouseY = _root._ymouse-this._y;
 if (nMouseX == 0 && nMouseY == 0) {
  var nDegrees = 0;
 } else {
  var nDegrees = Math.atan2(nMouseY, nMouseX)*180/Math.PI;
}
this._rotation = nDegrees;
}

FlashとWave

sinカーブを位置に変換する。

public function onEnterFrame(event:Event) {
ball.x += xspeed;
ball.y = centerY + Math.sin(angle) * range;
angle += yspeed;
}

sinカーブをスケールに変換する。

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

flashとcolor


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

red = color24 >> 16;
green = color24 >> 8 & 0xFF;
blue = color24 & 0xFF;

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