Re: CGShading line, triangle?
Re: CGShading line, triangle?
- Subject: Re: CGShading line, triangle?
- From: Henry McGilton <email@hidden>
- Date: Tue, 9 Dec 2003 09:49:23 -0800
On Tuesday, December 9, 2003, at 01:45 AM, Alastair Houghton wrote:
On 9 Dec 2003, at 02:33, Alex Eddy wrote:
Is there any straightforward way to gradient fill a triangle in Cocoa
or CoreGraphics, where each corner has a different color?
For that matter, what about gradient filling a thick line, taking into
account the line pattern and end cap style?
It looks like CGShading only supplies linear and radial fills which
won't do the triangle case, and it just fills the current clip path,
which means to fill a wide line with round end caps I'll have to do
all the geometry calculations myself to build the line.
Is it really this un-featured? Is there a clever workaround?
I think you can probably do what you want with a triangle using
multiple linear CGShadings (hint: you can fade the colour at the corner
down to transparent towards the other end of the triangle). My
intuition suggests that two CGShadings should be sufficient, although
using three might make it easier.
I suspect that what Alex wants here is a Gouraud shader. Looks like
CGShading is pretty limited --- axial and radial only?!?
One way to do Gouraud is via triangle subdivision, and at each
subdivision
you interpolate the colours to create new colours for the vertices of
the
new triangles.
Alex, if you are interested I can send you some (very basic, still under
construction, groping for direction) Gouraud shader code.
As far as doing a gradient fill of a thick line, I don't know any way
of getting the line's outline as a path, which is what you'd need in
order to do this. I think you'd have to convert it to a path manually;
it doesn't look stunningly tricky to do the necessary geometry.
At first glance, you should be able to use the Axial shader with a clip
path that is constructed using NSBezierPath. What in the Axial shader
is
not doing what you want?
BTW, the triangle thing would be easier (and hardware accelerated) in
OpenGL, if that's an option.
Best Wishes,
........ Henry
===============================+============================
Henry McGilton, Boulevardier | Trilithon Software
Objective-C/Java Composer | Seroia Research
-------------------------------+----------------------------
mailto:email@hidden |
http://www.trilithon.com
|
===============================+============================
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.