ActionScript 3プレミアムアニメーションチュートリアルノート

3099 ワード

2012.3.14
基本三角関数の計算:
角の正弦波値=対辺/斜辺
角のコサイン値=隣接/斜辺
角の正接=対/隣接
角度方式と弧度方式の相互変換:
円弧=角度*Math.PI/180角度=弧度*180/Math.PI
マウスへの回転(またはポイントへの回転):

// substitute mouseX, mouseY with the x, y point to rotate to 
 dx = mouseX - sprite.x; 
 dy = mouseY - sprite.y;
 sprite.rotation = Math.atan2(dy, dx) * 180 / Math.PI;

波形を作成するには

// assign value to x, y or other property of sprite or movie clip, 
// use as drawing coordinates, etc.
public function onEnterFrame(event:Event){
 value = center + Math.sin(angle) * range;
 angle += speed; 
}

円形を作成:

// assign position to x and y of sprite or movie clip, 
// use as drawing coordinates, etc. 
public function onEnterFrame(event:Event){
 xposition = centerX + Math.cos(angle) * radius;
 yposition = centerY + Math.sin(angle) * radius; angle += speed; 
}

楕円を作成するには
 
// assign position to x and y of sprite or movie clip, 
// use as drawing coordinates, etc. 
public function onEnterFrame(event:Event){
 xposition = centerX + Math.cos(angle) * radiusX;
 yposition = centerY + Math.sin(angle) * radiusY;
 angle += speed;
}

2点間の距離を計算します.

// points are x1, y1 and x2, y2 
// can be sprite / movie clip positions, mouse coordinates, etc. 
 dx = x2 – x1;
 dy = y2 – y1;
 dist = Math.sqrt(dx*dx + dy*dy);

10進数に変換:
trace(hexValue);
10進数から16進数に変換:

 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 is the point you want to draw through 
// x0, y0 and x2, y2 are the end points of the curve
 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;