[cairo] plots of contiguous rectangles

Travis Griggs tgriggs at cincom.com
Wed Aug 8 14:36:54 PDT 2007


On Aug 8, 2007, at 9:50, Tamas K Papp wrote:

> Hi,
>
> I am drawing plots of contiguous rectangles (a grid of rectangles,
> each with different color, to represent a 2d function).  The
> boundaries of the rectangles are not integers.
>
> When using a bitmap surface w/ white background, white lines appear
> between the rectangles -- I guess this is an artifact of antialiasing.
> Adding 0.5 on the sides gets rid of this, but then on the edge of the
> rectangles, artifacts appear from drawing twice (see left side of
> attached image).
>
> How could I get rid of both?  Snapping to integer grids is something I
> want to avoid: I am drawing on vector and bitmap surfaces, and I would
> have to keep tack of which is which.  But if there is not other
> solution, I can try to manage that, I just need to know.

I'm going to assume looking at that little graphic, that you're  
drawing a "temperature" scale, and doing so with different color  
blocks. The problem you site is a general one, and it's nice to see  
the responses, but I'm wondering for at least that particular part,  
if you can't sidestep the whole thing nicely by just using a linear  
gradient?

pseudo coding here...
gradient = LinearGradient from(0,0) to (0,1)
for (i = 0; i <= 1; i+=0.01)
{
	gradient addColorStop(i, (Color hue(1 - (i * 0.333)))
}
gradient scale (0, viewHeight)
cr source(gradient)
cr path(yourRectangle)
cr fill

You may be able to get away with an increment of just 0.1, you have  
to play to see how resolute you need it.

--
Travis Griggs
Objologist
"I choose. Therefore, I Am"


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20070808/a73033ba/attachment.html 


More information about the cairo mailing list