Gradients in Enable

A little while ago I added basic support for gradients in Kiva (and thus Enable). Its been slowly improving, and I think its at a point where it should be shared with a greater audience. Kiva now supports linear and radial gradients as path fills. My goal is to support the majority of what the SVG spec requires, currently we pass about 1/2 to 2/3 of the compliance tests.

I have added a couple of full examples in Enable/examples/kiva, here is an excerpt:
[sourcecode language=”python”]
# colors are 5 doubles: offset, red, green, blue, alpha
starting_color = numpy.array([0.0, 1.0, 1.0, 1.0, 1.0])
ending_color = numpy.array([1.0, 0.0, 0.0, 0.0, 1.0])

# diagonal
numpy.array([starting_color, ending_color]),
That is all the code required to draw a rectangle with a diagonal gradient. And here is a screenshot of the example I took this from:

kiva gradient screenshot

Leave a Reply

Your email address will not be published. Required fields are marked *

Please leave these two fields as-is:

Protected by Invisible Defender. Showed 403 to 101,646 bad guys.