Featured post
objective c - Having a hard time understanding NSBezierPath's curveToPoint: method -
i'm trying grips drawing (fairly basic) shapes in cocoa. understand how create paths straight edges (duh!), when comes doing curves, can't head around inputs produce shaped curve. specifically, have no idea how controlpoint1:
, controlpoint2:
arguments method influence shape.
i'm trying approximate shape of tab in google chrome:
and code i'm using is:
-(void)drawrect:(nsrect)dirtyrect { nssize size = [self bounds].size; cgfloat height = size.height; cgfloat width = size.width; nsbezierpath *path = [nsbezierpath bezierpath]; [path setlinewidth:1]; [path movetopoint:nsmakepoint(0, 0)]; [path curvetopoint:nsmakepoint(width * 0.1, height) controlpoint1:nsmakepoint(width * 0.05, height) controlpoint2:nsmakepoint(width * 0.03, height * 0.05)]; [path linetopoint:nsmakepoint(width * 0.9, height)]; [path curvetopoint:nsmakepoint(width, 0) controlpoint1:nsmakepoint(width * 0.95, height) controlpoint2:nsmakepoint(width * 0.97, height * 0.05)]; [path closepath]; [[nscolor colorwithcalibratedwhite:0.98 alpha:1] set]; [path fill]; [[nscolor colorwithcalibratedwhite:0.6 alpha:1] set]; [path stroke]; }
i'm failing horribly.
see, why can't have nice things :(
can give me pointers how think when comes drawing curves? example draws path great too, it's understanding these inputs curvetopoint:controlpoint1:controlpoint2:
that's holding me back.
update | @ahruman's answer got start taking shape. it's not 100% (missing curves on bottom corners, it's symmetrical shape @ least :)
the line between current drawing point (implicit) , control point 1 tangent of curve @ beginning. line between control point 2 , “to” point tangent @ end of curve. these correspond ends of 2 tangent controls see in vector drawing application bézier paths. if haven’t used one, inkscape free.
- Get link
- X
- Other Apps
Comments
Post a Comment