Вот обновочка... Учёл все замечания. Треугольник выровнялся, но всю верёвку немного клонит влево... Не могу понять, почему..=(

Код:
package
{
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class Main extends Sprite
{
private var pt:Array = new Array();
private var particles:Sprite = new Sprite();
private var canvas:Shape = new Shape();
private var grav:Number = 5;
// ========================================================== //
public function Main():void
{
stage.frameRate = 40;
addChild(canvas);
addChild(particles);
pt.push(new Particle(270,150));
pt.push(new Particle(270,175));
pt.push(new Particle(270,200));
pt.push(new Particle(270,225));
pt.push(new Particle(270,250));
pt.push(new Particle(270,275));
pt.push(new Particle(255,285));
pt.push(new Particle(285,285));
for (var i in pt)
{
particles.addChild(pt[i]);
}
addEventListener(Event.ENTER_FRAME, checkJoints);
addEventListener(Event.ENTER_FRAME, ptMouse);
}
// ========================================================== //
private function checkJoints(event:Event):void
{
var dx:Number;
var dy:Number;
canvas.graphics.clear();
// Gravity
for (var i in pt)
{
dx = (pt[i].x - pt[i].old_x);
dy = (pt[i].y - pt[i].old_y) + grav;
pt[i].old_x = pt[i].x;
pt[i].old_y = pt[i].y;
pt[i].x += dx/1.1;
pt[i].y += dy/1.1;
}
// Joints
for (var z:int=0; z<5; z++)
{
mouseJoint(pt[0], pt[1], 25);
ptJoint(pt[1], pt[2], 25);
ptJoint(pt[2], pt[3], 25);
ptJoint(pt[3], pt[4], 25);
ptJoint(pt[4], pt[5], 25);
ptJoint(pt[5], pt[6], 25);
ptJoint(pt[5], pt[7], 25);
ptJoint(pt[6], pt[7], 25);
}
// Lines
drawLine(pt[1], pt[2]);
drawLine(pt[2], pt[3]);
drawLine(pt[3], pt[4]);
drawLine(pt[4], pt[5]);
drawLine(pt[5], pt[6]);
drawLine(pt[5], pt[7]);
drawLine(pt[6], pt[7]);
}
// ========================================================== //
private function ptMouse(event:Event):void
{
pt[0].x = mouseX;
pt[0].y = mouseY;
drawLine(pt[0], pt[1]);
}
// ========================================================== //
private function mouseJoint(p1:Particle, p2:Particle, len:int):void
{
var dx:Number;
var dy:Number;
var d_len:Number;
var diff:Number;
dx = p2.x-p1.x;
dy = p2.y-p1.y;
d_len = Math.sqrt(dx*dx + dy*dy);
diff = (d_len-len)/d_len;
dx *= diff;
dy *= diff;
p2.x -= dx;
p2.y -= dy;
}
// ========================================================== //
private function ptJoint(p1:Particle, p2:Particle, len:int):void
{
var dx:Number;
var dy:Number;
var d_len:Number;
var diff:Number;
dx = p2.x-p1.x;
dy = p2.y-p1.y;
d_len = Math.sqrt(dx*dx + dy*dy);
diff = (d_len-len)/d_len;
dx *= 0.5*diff;
dy *= 0.5*diff;
p2.x -= dx;
p2.y -= dy;
p1.x += dx;
p1.y += dy;
}
// ========================================================== //
private function drawLine(p1:Particle, p2:Particle):void
{
canvas.graphics.lineStyle(1,0x000000);
canvas.graphics.moveTo(p1.x,p1.y);
canvas.graphics.lineTo(p2.x, p2.y);
}
// ========================================================== //
}
}
// ***** [ Particle Class ] ***************************************** //
import flash.display.Sprite;
internal class Particle extends Sprite
{
public var old_x:Number;
public var old_y:Number;
// ========================================================== //
public function Particle(_x:int, _y:int):void
{
x = _x;
y = _y;
old_x = _x;
old_y = _y;
graphics.lineStyle(1, 0x000000);
graphics.beginFill(0xFFD22B);
graphics.drawCircle(0,0,5);
graphics.endFill();
}
// ========================================================== //
}