NSBezierPath, Accessing elements of a NSBezierPath path
NSBezierPath, Accessing elements of a NSBezierPath path
- Subject: NSBezierPath, Accessing elements of a NSBezierPath path
- From: Michel Haver <email@hidden>
- Date: Thu, 12 Jul 2001 15:12:05 +0200
I have a question about NSBezierPath functionality from the Application Kit
API Reference: Objective-C:
NSBezierPath
Accessing elements of a NSBezierPath path
- elementCount
- elementAtIndex:
- elementTypeAtIndex:associatedPoints:
- removeAllPoints
- setAssociatedPoints:atIndex:
NSBezierPath defines several methods for obtaining information about the
path elements (and their associated points) directly, including
elementAtIndex:, and elementTypeAtIndex:associatedPoints: among others. You
could use these methods to break down a path and reconstruct it point by
point.
Nice, but how does it work.
How can I access the elements of the CirclePath by using these accessors?
If I draw a Circle by using NSBezierPath how can I extract for example 12
points from the Circle, each with a 30 degrees (360/12) difference to each
other.
Thanks for all the help so far.
Code to drawCircle
- (void)drawCircle
{
NSBezierPath *circleToDraw;
NSAffineTransform *translationMatrix;
NSAffineTransform *scaleMatrix;
//Make the Circle grow with resizing MyView
NSRect myBounds = [self bounds];
//Make screenLocation grow with the NSView
//NSPoint screenLocation = NSMakePoint(50, 50);
NSPoint screenLocation = NSMakePoint(myBounds.size.width/2.0,
myBounds.size.height/2.0);
NSColor *circleStrokeColor = [NSColor blackColor];
// NSColor *circleStrokeColor = [NSColor blueColor];
// NSColor *circleFillColor = [NSColor blueColor];
float circleRadius = 150.0;
translationMatrix = [NSAffineTransform transform];
[translationMatrix translateXBy: screenLocation.x yBy:
screenLocation.y];
scaleMatrix = [NSAffineTransform transform];
[scaleMatrix scaleBy: circleRadius];
[scaleMatrix appendTransform:translationMatrix];
circleToDraw = [scaleMatrix transformBezierPath:[self circlePath]];
// [circleFillColor set];
// [circleToDraw fill];
[circleStrokeColor set];
[circleToDraw setLineWidth:2.0];
[circleToDraw stroke];
}
Cheers,
Michel