nannou icon indicating copy to clipboard operation
nannou copied to clipboard

How to draw a line with a color gradient?

Open bzm3r opened this issue 4 years ago • 2 comments

We cannot pass a Gradient object to a points_colored, so how can we draw a line that has a color gradient according its path?

bzm3r avatar Jan 08 '21 20:01 bzm3r

@bzm3r Maybe there's a better way and I haven't actually tried, but as a workaround you could try to render the gradient into a texture and use points_textured instead.

lzurbriggen avatar Jan 09 '21 14:01 lzurbriggen

I think this is shown in the draw_polyline example. It doesn’t use Gradient specifically, but you can do it yourself. You have to manually apply the Gradient by setting the Gradient’s domain to the length of the line and using Gradient.get() for each vertex.

zmitchell avatar Jan 21 '21 03:01 zmitchell