As常用的公式（留着） 原

zhenghuazhi

dx = x2 – x1;

dy = y2 – y1;

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

maps.x = maps.x-(maps.x-mouseX)/5;  //////跟随鼠标

//==========================================================================================================

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;

//=====================================================

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);

//判断碰撞需要知道两个 ball 之间的角度，使用 Math.atan2(dy, dx)

var angle:Number = Math.atan2(dy, dx); var sin:Number = Math.sin(angle); var cos:Number = Math.cos(angle);

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;

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<numObjects; j++) {

//使用变量 j 提取引用

var objectB = objects[j];

//在 objectA 与 objectB 之间进行碰撞检测

}

}

dx = mouseX - sprite.x;

dy = mouseY - sprite.y;

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

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

//======================================================mass=质量  vx为速度

var vx0Final:Number = ((ball0.mass - ball1.mass) * ball0.vx + 2 * ball1.mass * ball1.vx) / (ball0.mass + ball1.mass);

//===================================================================================================优化后的代码

var vxTotal:Number = ball0.vx - ball1.vx;

ball0.vx = ((ball0.mass - ball1.mass) * ball0.vx + 2 * ball1.mass * ball1.vx) / (ball0.mass + ball1.mass);

ball1.vx = vxTotal + ball0.vx;

//=============================================

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;

}

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 {

angle+=speed;

}

public function onEnterFrame(event:Event):void {

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 << 16 | green << 8 | blue;

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

// 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);

zhenghuazhi

2006/07/30
0
0
__bridge、__bridge_retain、__bridge_transfer讲解

2018/05/13
0
0

很多人都会有一个疑问，为什么同样的作为一个编程人员，有的人只能拿5-6K，有的人能1W+，当然这其中可能有工作年限的因素，也有经验因素。但还有你不知道的专业因素。那就是你不知道下面...

UG数控编程
2018/04/24
0
0
MimbleWimble 系列之Pedersen 承诺

MW协议中几个主要的概念 Pedersen 承诺 交易合并 范围证明 蒲公英路由 Pedersen承诺-用来达到匿名保密交易的协议，简单来说你转给我5个token，在其他人不知道数额和地址的情况下，保证这笔交...

2019/03/14
58
0

ThinkCMF
2014/07/26
1.7W
24

61
0
Kettle自定义jar包供javascript使用

CREATE_17

106
0

javail

79
0

SongAlone

128
0

shzwork

85
0