flex 实用公式
实用公式
第三章
基础三角函数的计算:
角的正弦值 = 对边 / 斜边
角的余弦值 = 邻边 / 斜边
角的正切值 = 对边 / 邻边
弧度转换为角度以及角度转换为弧度:
弧度 = 角度 * Math.PI / 180
角度 = 弧度 * 180 / Math.PI
向鼠标(或者任何一个点)旋转:
// 用要旋转到的 x, y 坐标替换 mouseX, mouseY
dx = mouseX - sprite.x;
dy = mouseY - sprite.y;
sprite.rotation = Math.atan2(dy, dx) * 180 / Math.PI;
创建波形:
// 将 x, y 或其它属性赋值给 Sprite 影片或影片剪辑,
// 作为绘图坐标,等等。
public function onEnterFrame(event:Event){
value = center + Math.sin(angle) * range;
angle += speed;
}
创建圆形:
// 将 x, y 或其它属性赋值给 Sprite 影片或影片剪辑,
// 作为绘图坐标,等等。
public function onEnterFrame(event:Event){
xposition = centerX + Math.cos(angle) * radius;
yposition = centerY + Math.sin(angle) * radius;
angle += speed;
}
创建椭圆:
// 将 x, y 或其它属性赋值给 Sprite 影片或影片剪辑,
// 作为绘图坐标,等等。
public function onEnterFrame(event:Event){
xposition = centerX + Math.cos(angle) * radiusX;
yposition = centerY + Math.sin(angle) * radiusY;
angle += speed;
}
获得两点间的距离:
// x1, y1 和 x2, y2 是两个点
// 也可以是 Sprite / MovieClip 坐标,鼠标坐标,等等。
dx = x2 – x1;
dy = y2 – y1;
dist = Math.sqrt(dx*dx + dy*dy);
第四章
十六进制转换为十进制:
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 是我们想要穿过的一点
// x0, y0 以及 x2, y2 是曲线的两端
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;
第六章
移除出界对象:
if(sprite.x - sprite.width / 2 > right ||
sprite.x + sprite.width / 2 < left ||
sprite.y – sprite.height / 2 > bottom ||
sprite.y + sprite.height / 2 < top)
{
// 删除影片的代码
}
重置出界对象:
if(sprite.x - sprite.width / 2 > right ||
sprite.x + sprite.width / 2 < left ||
sprite.y – sprite.height / 2 > bottom ||
sprite.y + sprite.height / 2 < top)
{
// 重置影片的位置和速度
}
屏幕环绕出界对象:
if(sprite.x - sprite.width / 2 > right)
{
sprite.x = left - sprite.width / 2;
}
else if(sprite.x + sprite.width / 2 < left)
{
sprite.x = right + sprite.width / 2;
}
if(sprite.y – sprite.height / 2 > bottom)
{
sprite.y = top – sprite.height / 2;
}
else if(sprite.y + sprite.height / 2 < top)
{
sprite.y = bottom + sprite.height / 2;
}
摩擦力应用(正确方法):
speed = Math.sqrt(vx * vx + vy * vy);
angle = Math.atan2(vy, vx);
if(speed > friction)
{
speed -= friction;
}
else
{
speed = 0;
}
vx = Math.cos(angle) * speed;
vy = Math.sin(angle) * speed;
摩擦力应用(简便方法):
vx *= friction;
vy *= friction;
第八章:
简单缓动运动,长形:
var dx:Number = targetX - sprite.x;
var dy:Number = targetY - sprite.y;
vx = dx * easing;
vy = dy * easing;
sprite.x += vx;
sprite.y += vy;
简单缓动运动,中形:
vx = (targetX - sprite.x) * easing;
vy = (targetY - sprite.y) * easing;
sprite.x += vx;
sprite.y += vy;
简单缓动运动,短形:
sprite.x += (targetX - sprite.x) * easing;
sprite.y += (targetY - sprite.y) * easing;
简单弹性运动,长形:
var ax:Number = (targetX - sprite.x) * spring;
var ay:Number = (targetY - sprite.y) * spring;
vx += ax;
vy += ay;
vx *= friction;
vy *= friction;
sprite.x += vx;
sprite.y += vy;
简单弹性运动,中形:
vx += (targetX - sprite.x) * spring;
vy += (targetY - sprite.y) * spring;
vx *= friction;
vy *= friction;
sprite.x += vx;
sprite.y += vy;
简单弹性运动,短形:
vx += (targetX - sprite.x) * spring;
vy += (targetY - sprite.y) * spring;
sprite.x += (vx *= 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;
// 如前例弹性运动到 targetX, targetY
第九章
距离碰撞检测:
// 从影片 spriteA 和 spriteB 开始
// 如果使用一个空白影片,或影片没有半径(radius)属性
// 可以用宽度或高度除以 2。
var dx:Number = spriteB.x - spriteA.x;
var dy:Number = spriteB.y - spriteA.y;
var dist:Number = Math.sqrt(dx * dx + dy * dy);
if(dist < spriteA.radius + spriteB.radius)
{
// 处理碰撞
}
多物体碰撞检测:
var numObjects:uint = 10;
for(var i:uint = 0; i < numObjects - 1; i++)
{
// 使用变量 i 提取引用
var objectA = objects[i];
for(var j:uint = i+1; j
{
// // 使用变量 j 提取引用
var objectB = objects[j];
// perform collision detection
// between objectA and objectB
}
}
第十章
坐标旋转:
x1 = Math.cos(angle) * x - Math.sin(angle) * y;
y1 = Math.cos(angle) * y + Math.sin(angle) * x;
反坐标旋转:
x1 = Math.cos(angle) * x + Math.sin(angle) * ;y
y1 = Math.cos(angle) * y - Math.sin(angle) * x;
第十一章
动量守恒的数学表达式:
(m0 – m1) * v0 + 2 * m1 * v1
v0Final = ----------------------------------------------
m0 + m1
(m1 – m0) * v1 + 2 * m0 * v0
v1Final = ---------------------------------------------
m0 + m1
动量守恒的 ActionScript 表达式,短形:
var vxTotal:Number = vx0 - vx1;
vx0 = ((ball0.mass - ball1.mass) * vx0 +
2 * ball1.mass * vx1) /
(ball0.mass + ball1.mass);
vx1 = vxTotal + vx0;
第十二章
引力的一般公式:
force = G * m1 * m2 / distance2
ActionScript 实现万有引力:
function gravitate(partA:Ball, partB:Ball):void
{
var dx:Number = partB.x - partA.x;
var dy:Number = partB.y - partA.y;
var distSQ:Number = dx * dx + dy * dy;
var dist:Number = Math.sqrt(distSQ);
var force:Number = partA.mass * partB.mass / distSQ;
var ax:Number = force * dx / dist;
var ay:Number = force * dy / dist;
partA.vx += ax / partA.mass;
partA.vy += ay / partA.mass;
partB.vx -= ax / partB.mass;
partB.vy -= ay / partB.mass;
}
第十四章
余弦定理
a2 = b2 + c2 - 2 * b * c * cos A
b2 = a2 + c2 - 2 * a * c * cos B
c2 = a2 + b2 - 2 * a * b * cos C
ActionScript 的余弦定理:
A = Math.acos((b * b + c * c - a * a) / (2 * b * c));
B = Math.acos((a * a + c * c - b * b) / (2 * a * c));
C = Math.acos((a * a + b * b - c * c) / (2 * a * b));
第十五章
基本透视法:
scale = fl / (fl + zpos);
sprite.scaleX = sprite.scaleY = scale;
sprite.alpha = scale; // 可选
sprite.x = vanishingPointX + xpos * scale;
sprite.y = vanishingPointY + ypos * scale;
Z 排序:
// 假设有一个带有 zpos 属性的 3D 物体的数组
objectArray.sortOn("zpos", Array.DESCENDING | Array.NUMERIC);
for(var i:uint = 0; i < numObjects; i++)
{
setChildIndex(objectArray[i], i);
}
坐标旋转:
x1 = cos(angleZ) * xpos - sin(angleZ) * ypos;
y1 = cos(angleZ) * ypos + sin(angleZ) * xpos;
x1 = cos(angleY) * xpos - sin(angleY) * zpos;
z1 = cos(angleY) * zpos + sin(angleY) * xpos;
y1 = cos(angleX) * ypos - sin(angleX) * zpos;
z1 = cos(angleX) * zpos + sin(angleX) * ypos;
3D 距离:
dist = Math.sqrt(dx * dx + dy * dy + dz * dz); '
ref:http://www.cnblogs.com/liongis/archive/2010/08/10/1796558.html
Jul 21, 2023 03:12:33 PM
Gujarat Conducts the Examination for 4th to Examine the knowledge and Academic Progress of Students and Promote Them to a High School Level, Primary Students are Advised to get Familiar with the Gujarat Syllabus 2024 Details Thoroughly before Starting Preparing for the Examination 2024.Gujarat Board Maths, EVS, English and Gujarati Syllabus 2024 are Designed with the idea to Foster Creative Gujarat 4th Class Syllabus 2024 Thinking and the Intelligence of Primary School Students, Students who wish to Score High in the Exam, can now Download the Syllabus and Start Studying for the Exam 2024, Students of Both Elementary Various Class Could Download the GCERT Syllabus 2024 as PDF format.
Aug 24, 2024 12:43:36 AM
Actually I read it yesterday but I had some thoughts about it and today I wanted to read it again because it is very well written. Kissimmee Termite Treatment
Aug 24, 2024 12:43:47 AM
This is very useful, although it will be important to help simply click that web page link: Orlando Bed Bug Treatment
Aug 24, 2024 12:43:57 AM
I simply want to tell you that I am new to weblog and definitely liked this blog site. Very likely I’m going to bookmark your blog . You absolutely have wonderful stories. Cheers for sharing with us your blog. Oviedo Bed Bug Treatment
Sep 28, 2024 07:40:12 PM
These you will then see the most important thing, the application provides you a website a powerful important internet page: فني كاميرات مراقبة الكويت
Oct 10, 2024 01:12:15 PM
I should say only that its awesome! The blog is informational and always produce amazing things. Nassau County CPA firm
Oct 13, 2024 09:58:35 PM
Here you will learn what is important, it gives you a link to an interesting web page: buy instagram reels views
Oct 16, 2024 08:42:52 PM
You bear through a awesome vacancy. I sanity definitely quarry it moreover personally suggest to my buddys. I am self-possessed they determination be benefited from this scene. فتح ابواب
Dec 20, 2024 06:39:34 PM
On this subject internet page, you'll see my best information, be sure to look over this level of detail. بنشر متنقل