I'm trying to draw a power function curve in a 300x300 pixel rectangle using NSBezierPath as follows:
-(void)drawPowerCurve:(float)power points:(int)numbPoints{
NSBezierPath * path = [NSBezierPath bezierPath];
[path setLineWidth: 1.0];
[[NSColor colorWithCalibratedRed:0.0 green:0.0 blue:1.0 alpha:1.0] set];
NSPoint borderOrigin = {35.5,15.5};
NSPoint endPoint;
[path moveToPoint:borderOrigin];
for(int i = 0; i < numbPoints; i++){
endPoint.x = borderOrigin.x + (300.0/numbPoints)*(i+1);
endPoint.y = borderOrigin.y + 300.0*pow(((i+1)/(float)numbPoints), power);
[path lineToPoint:endPoint];
[path stroke];
[path moveToPoint:endPoint];
}
}
However, the curve thins out at the top end compared to the bottom end. For example power = 1.8 and numbPoints = 50. Also the curve doesn't look as smooth as for example curves shown in Apple's ColorSync Utility. Of course I don't know how they are drawing the curves in ColorSync. Any ideas on how to improve the look of these curves (particularly getting rid of the thining out).
Move the stroke
out of the loop so you only draw the curve once instead of numbPoints
times as it grows. Also remove the redundant moveToPoint
in the loop, lineToPoint
leaves the current point at the end of the added segment.