02-22-2011, 07:12 PM
#1 (permalink )
Registered Member
Join Date: Feb 2011
Posts: 122
Change RGBStrokeColor mid-path
Hi,
I'm trying to draw a quadratic bezier curve to the screen, with a line connecting the two endpoints below. My current code is as follows:
Code:
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);
CGContextSetLineWidth(context, 3.0);
CGContextBeginPath(context);
CGContextMoveToPoint(context, [[beginPointsXQuad objectAtIndex:index] floatValue],
[[beginPointsYQuad objectAtIndex:index] floatValue]);
CGContextAddQuadCurveToPoint(context, [[controlPointsXQuad objectAtIndex:index] floatValue],
[[controlPointsYQuad objectAtIndex:index] floatValue],
[[endPointsXQuad objectAtIndex:index] floatValue],
[[endPointsYQuad objectAtIndex:index] floatValue]);
CGContextStrokePath(context); //????
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextSetLineWidth(context, 4.0);
CGContextAddLineToPoint(context, [[beginPointsXQuad objectAtIndex:index] floatValue],
[[beginPointsYQuad objectAtIndex:index] floatValue]);
CGContextClosePath(context); //????
CGContextDrawPath(context, kCGPathFillStroke); //????
As you may be able to tell, I want the curve to be outlined in black and the bottom line to be outlined in white, the fill being white. It doesn't seem to work to stroke path and then do some more stuff. So how can I merge the two colors, or do I have to "cheat?"
02-22-2011, 07:54 PM
#2 (permalink )
Cocoa Junkie
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Quote:
Originally Posted by
architectpianist
Hi,
I'm trying to draw a quadratic bezier curve to the screen, with a line connecting the two endpoints below. My current code is as follows:
Code:
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);
CGContextSetLineWidth(context, 3.0);
CGContextBeginPath(context);
CGContextMoveToPoint(context, [[beginPointsXQuad objectAtIndex:index] floatValue],
[[beginPointsYQuad objectAtIndex:index] floatValue]);
CGContextAddQuadCurveToPoint(context, [[controlPointsXQuad objectAtIndex:index] floatValue],
[[controlPointsYQuad objectAtIndex:index] floatValue],
[[endPointsXQuad objectAtIndex:index] floatValue],
[[endPointsYQuad objectAtIndex:index] floatValue]);
CGContextStrokePath(context); //????
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextSetLineWidth(context, 4.0);
CGContextAddLineToPoint(context, [[beginPointsXQuad objectAtIndex:index] floatValue],
[[beginPointsYQuad objectAtIndex:index] floatValue]);
CGContextClosePath(context); //????
CGContextDrawPath(context, kCGPathFillStroke); //????
As you may be able to tell, I want the curve to be outlined in black and the bottom line to be outlined in white, the fill being white. It doesn't seem to work to stroke path and then do some more stuff. So how can I merge the two colors, or do I have to "cheat?"
If I remember correctly, paths don't save a color. They use the attributes of the current pen (size and color, stipple pattern, etc.). You'll have to break the path into 2 in order to draw it in different parts.
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 379
18 members and 361 guests
Absentia , akphyo , apatsufas , BinHex , cpsclicker , dre , Error404 , Gaz , gmarro , jeroenkeij , Kirkout , mottdog , Music Man , PavelMik , teebee74 , whitey99 , Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,666
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, cpsclicker