[cairo] Path Gradients
spitzak at thefoundry.co.uk
Thu Jan 3 19:28:36 PST 2008
Okay, it is shading with the gradient in straight lines between a fixed
point and the points on the path. There is some mysteries there:
sometimes it indicates that the "brush" can have a different path than
the fill, but there are no examples where they differ. Also no examples
of what happens if the center point is outside the path or not connected
by a straight line to one of the edges due to a non-convex path.
In truth this only looks useful to make the same results that Cairo does
with radial gradients. Shapes that are not round are pretty useless due
to Mach banding (this is the starburst rays you see). However I can
certainly see that this is a more convienent way to specify a radial
It is plausable that sufficent emulation could be done by finding the
bounding box of the path and using that and the center point to make a
Cairo radial pattern. This would never produce Mach banding and maybe is
close enough or even better for all the graphics where you do want it.
An alternative would be to directly support this and remove radial
gradients from Cairo. Radial gradients could be emulated by drawing with
this into an off-screen surface and using that as a source.
Bobby Salazar wrote:
> I'm afraid that everyone is searching for the perfect solution to this and everyone's idea of a perfect solution is different, and so it will never move past discussions. Unfortunately, I know very little about graphics and shading algorithms or I might try to implement it myself. That is why I think a bounty may help.
> I've spent some time surfing the net and researching the GDI+ path gradients and it is actually far more complex than what I'm after. But it does allow very advanced gradients to be created. I especially liked the 2-color bell gradient concept (explained in the first link below). Here are some web pages that I found especially informative about GDI+ path gradients:
> I guess what I'm really looking for is a way to get a "path-shaped" gradient from a given center point to the edges of the (current) path. Where the gradient would use the color stops to produce the colors out to the edge of the path. I'd be interested in a more capable implementation of path gradients eventually, but I doubt I would ever use it due to the complexity. So a simple path, color stops and center point is what I'm really after, as seen in these images (except for the triangle in the last one):
More information about the cairo