graphics.curveTo through point

When I was doing the rope demo a few posts down I had to use the graphics.curveTo, but get it curve through a point instead of using the point as a control. I found a function a while back that I’ll try to source so I take no credit for it, but this is my revision of if.

function curveThroughPoint($start:Point,$mid:Point, $end:Point ):Point
{
return new Point( 2 * $mid.x - 0.5 * ( $start.x + $end.x ), 2 * $mid.y - 0.5 * ( $start.y + $end.y ) );
}

Then you can use something like

var startPos:Point = new Point( 100, 100 );
var midPos:Point = new Point( 200, 200 );
var endPos:Point = new Point( 300, 300 );

midPos = curveThroughPoint( startPos, midPos, endPos );

this.graphics.lineStyle( 2,0x000000 );
this.graphics.moveTo( startPos.x, startPos.y );
this.graphics.curveTo( midPos.x, midPos.y, endPos.x, endPos.y );


here’s me quickbox2d rope example that used it

This entry was posted in flash. Bookmark the permalink.

One Response to graphics.curveTo through point

  1. Pingback: Quickbox2d string and balls « Mike R :: R ekim