• I haven’t done any Flash in the longest time, but for work I am developing a dynamic route map which needs to draw lines between locations on the fly. Now I could have just gone in for straight lines, but I really wanted some neat curvature in there.

    A quick Google turned up the curveTo() method, which accepts 4 arguments, the x/y co-ordinates for the control point and the end point. After a few hours of racking my brains to recall basic trigonometry (see kids, maths can come in useful after school). I had built a function to compute the control point for any given points. So that multiple curves drawn from the same destination looked similar, my control point would be 1/3 along the straight-line distance, and offset from that point by 1/4 at a 90 degree angle.

    I was pretty pleased with myself until I loaded up the .swf to see the curves going all over the place, never actually intersecting with the control points at all. After going through the calculations and proving my maths was correct, I finally dug around a little more to discover that curveTo() simply draws a curve towards the control point, rather than intersecting it. There’s a really neat Flash movie at PixelWit to explain:

    http://www.pixelwit.com/blog/2007/11/01/curveto-visualization

    After cursing myself for a while, I just altered the ratios a little to increase the curvature. The moral of all this? Google first, compute later.

    Posted by gbradley @ 12:56 pm

    Tags:

  • Comments are closed.