Drawing rectangles with interpolated colors (different color for each corner)

95 views
Skip to first unread message

Jean-Claude Monnin

unread,
Oct 21, 2012, 3:28:27 PM10/21/12
to skia-d...@googlegroups.com
I try to draw rectangles filled with an interpolated color form the corners (a different color assigned at each corner). 
I have a grid of data points that I would like to visualise on a map. I would like to fill the area of this grid with interpolated colors in between the data points. In OpenGL it's straightforward to achieve that with a quad- or tri-strip and assigning a color to each vertex.
I didn't find an obvious way to do that in Skia. How can this be done in Skia?

Thanks for your help.

Jean-Claude

Mike Reed

unread,
Oct 22, 2012, 8:11:52 AM10/22/12
to skia-d...@googlegroups.com
canvas->drawVertices(...)
> --
> You received this message because you are subscribed to the Google Groups
> "skia-discuss" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/skia-discuss/-/kny49fXx27YJ.
> To post to this group, send email to skia-d...@googlegroups.com.
> To unsubscribe from this group, send email to
> skia-discuss...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/skia-discuss?hl=en.

Jean-Claude Monnin

unread,
Oct 22, 2012, 8:44:20 AM10/22/12
to skia-d...@googlegroups.com
Oops, I missed that while checking the docs. This is exactly what I need. Thanks.

On Oct 22, 2012, at 14:11 , Mike Reed <re...@google.com> wrote:

> canvas->drawVertices(...)

Dave M

unread,
Dec 13, 2021, 5:47:06 AM12/13/21
to skia-discuss
hi, I have same trouble on it, but drawVertices can not make it, can  you   help me?

Mike Reed

unread,
Dec 13, 2021, 7:11:59 AM12/13/21
to skia-d...@googlegroups.com
A 4-corner gradient (inside a rect) is not a linear problem -- so it can't be done with just a couple of triangles. It is sort of bi-quadratic, in the same way that bilerp (image filtering) is quadratic (involves the product of u and v).

SkCanvas::drawPatch() can do this. It is more general, in that it can handle a cubic curve on each side of the 'rectangle', but you can easily specify the cubics to be straight lines.




--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/f6e55b64-b030-4186-84a4-98a8686447a4n%40googlegroups.com.


--
"I think I can safely say that nobody understands quantum mechanics." -- Richard Feynman
"It ain't what you don't know that gets you into trouble. It's what you know for sure that just ain't so." -- Mark Twain
"I am pleased to see that we have differences" -- Surak

Dave M

unread,
Dec 14, 2021, 4:54:43 AM12/14/21
to skia-discuss
Dear mi...@reedtribe.org   ,Thank you for the suggestion on  drawPatch() ,i make 4 straight lines, while the result is not i want ,  I feel depressed 。
i wander if i shader can make it?
图片1.png

Brian Salomon

unread,
Dec 14, 2021, 12:55:17 PM12/14/21
to skia-d...@googlegroups.com
The spacing of the interior control points on the edges of the quads affects how the color interpolation works out:


Maybe that's where the problem lies?



--

Brian Salomon | Office Hours: go/bsalomon-office | bsal...@google.com

Dave M

unread,
Dec 16, 2021, 8:57:42 PM12/16/21
to skia-discuss

Dear BS,thank you for your demo, i try it while produced little effect,  
maybe the problem is part of image data quality, can skia do image filter or smooth?
Reply all
Reply to author
Forward
0 new messages