as基本公式まとめ

2897 ワード

基本三角関数の計算:
角の正弦値=対辺/斜辺角の余弦値=隣/斜辺の正接値=2辺/隣
角度とラジアンの相互変換:
ラジアン=角度*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.ath 2(dy,dx)*180/Math.PI;
[b波形を作成:
// 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);
十進数を十六進数に変換します。
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);
2点の間の中点
x = (x1+x2) / 2;
y = (y1+y2) / 2;
角速度はx、y速度ベクトルに変換されます。
vx = speed * Math.cos(angle); 
vy = speed * Math.sin(angle);
角加速度(物体に作用するフォース)はxに変換され、y加速度:
ax = force * Math.cos(angle); 
ay = force * Math.sin(angle);
速度ベクトルに加速度を加える:
vx += ax; 
vy += ay;
速度ベクトルを座標に追加:
movieclip._x += vx; 
sprite.y += vy;