So I have a function which randomly generates some CGPoints I then create a CGPath from these points. I use this path in a keyframe animation to animate a view around the screen.
The path is generated using the code below:
- (CGMutablePathRef)generatePathFromCoordinates:(NSArray *)coordinates
{
CGMutablePathRef path = CGPathCreateMutable();
CGPoint point = [(NSValue *)[coordinates objectAtIndex:0] CGPointValue];
CGPathMoveToPoint(path, nil, point.x, point.y);
for (int i=1; i < coordinates.count; i++)
{
point = [(NSValue *)[coordinates objectAtIndex:i] CGPointValue];
CGPathAddLineToPoint(path, nil, point.x, point.y);
}
return path;
}
The above code works great but the animation looks a little strange, so I'd like to add a curve between coordinates rather than a straight line. Like the picture below (amazing paint skills i know!). Path 'A' is what I'm currently doing and path 'B' is what I'm aiming for:
After having a look at the functions available in the CGPath reference I can see a few which might get the job done, CGPathAddArcToPoint
CGPathAddCurveToPoint
. I've had a brief go at using these functions but wasn't able to get the desired effect (probably because I was using them incorrectly)
Could you guys point me in the right direction to achieve a nice curve?
Thanks in advance