The best way to reuse the path is probably the method for them. Make one where you add the starting coordinates, and return CGMutablePathRef so that you can draw it after the path is done.
Here's what it will look like based on the example you asked in your question:
-(CGMutablePathRef) drawHexagon:(CGPoint)origin { //create mutable path CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, nil, origin.x, origin.y); CGPoint newloc = CGPointMake(origin.x - 20, origin.y + 42); CGPathMoveToPoint(path, nil, newloc.x, newloc.y); CGPoint newloc = CGPointMake(newloc.x + 16, newloc.y + 38); CGPathMoveToPoint(path, nil, newloc.x, newloc.y); CGPoint newloc = CGPointMake(newloc.x + 49, newloc.y + 0); CGPathMoveToPoint(path, nil, newloc.x, newloc.y); CGPoint newloc = CGPointMake(newloc.x + 23, newloc.y - 39); CGPathMoveToPoint(path, nil, newloc.x, newloc.y); CGPoint newloc = CGPointMake(newloc.x - 25, newloc.y - 40); CGPathMoveToPoint(path, nil, newloc.x, newloc.y); CGPoint newloc = CGPointMake(newloc.x - 43, newloc.y + 0); //which should be you origin CGPathMoveToPoint(path, nil, newloc.x, newloc.y); CGPathCloseSubpath(path); return path; }
name it CGMutablePathRef path = [self drawHexagon:someStartingPoint];
Changed comments:
You can add the path to the context with: CGContextAddPath(context, path);
Then draw it, as it seems to you, for example: CGContextDrawPath(context, kCGPathFill);
Having added the path to the context should not be difficult.
This should work for you. Good luck.