Archive for the 'Kiva' category

Gradients in Enable

Jul 22 2009 Published by Bryce Hendrix under Enable, Kiva, NumPy

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:

# 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
gc.rect(50,25,150,100)
gc.linear_gradient(50,25,150,125,
    numpy.array([starting_color, ending_color]),
    "pad")
gc.draw_path()

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

No responses yet

Older posts »

Featuring Advanced Search Functions plugin by YD