1

I'm a newbie in this type of approach to programming since I really doesn't care for hardcore graphics generation. I design, write, run, and study parametrized climate models with python. But, at last, I have encountered myself with a visualization issue.

I was looking for something in Cairo library that allows me to map a linear gradient onto an arbitrary curve (not necessarily a circumference) such that there is a more or less smooth variation of colour (or shade) across my path. Then I have been looking for some pattern and I finally found that maybe mesh gradients in Cairo are the solution.

However, I can't create a new mesh gradient from my python script with cairo.pattern_create_mesh()!

Therefore, my questions are: How I use mesh gradients in Cairo? Is there any other simple way to do what I want with Cairo (I don't know, like a simple mapping from a line segment to a curve via parametrization, I know I ask too much)?

1 Answer 1

0

Mesh patterns were added in cairo 1.12 which is the latest release. Thus, most language bindings likely don't support them yet. I don't know anything about the combination of python and cairo and thus don't know any workaround.

I don't know any simple way to simulate what you need with other patterns, sorry. (Although I am not really sure how you want to do your mapping via mesh gradients either...)

3
  • For what I have read, basically Inkscape wiki and Illustrator help, for circumferences, one can use a conical gradient for obtaining what I want. I have seen Cairo, in its last version, can do that. I was wondering there was some generalization of that for an arbitrary smooth curve. As you said it, may be I have to wait for python bindings being update for using mesh gradients, of which conical ones are, as I understand, are a particular case of mesh gradients. Jan 25, 2013 at 17:40
  • The cheap trick that I'm thinking is, for the moment, the best, is divide curve in a large number of individual segments and to every segment assign a linear gradient on which the first stop is the last stop of the previous segment gradient. Obviously curve segments need to be small since you will be approximating, locally, the gradient direction through curve's tangent line. Then that could be a problem for a curve that has very small radius of curvature in some of its sections. Jan 25, 2013 at 17:54
  • The problem with that is: A linear gradient only has a single line. Thus I don't think that you can approximate your conical gradient this way. You would need some magic to directly draw this into an image surface... Jan 26, 2013 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.