We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I want to draw a connected line that consists of n vertices. These n vertices have different colors, so there should be a gradient applied. However, I can't figure out the correct method to do so.
What I have so far (waypoints is a list with objects that have an assigned color and a PVector position):
pushMatrix();
translate(map.getCenter().x, map.getCenter().y);
beginShape();
for(int i = 0; i < waypoints.size(); i++) {
noFill();
stroke(waypoints.get(i).getColor());
curveVertex(waypoints.get(i).getPosition().x, waypoints.get(i).getPosition().y);
}
endShape();
popMatrix();
This does not seem to work as the stroke is monochrome. Does anybody have an idea what I'm missing here? Is it only possible using lines(...) or is there also a way using vertices?
Thanks in advance!
ezkhimo
Answers
...
In your description you're only talking about lines, so if you don't need curves, you can set different stroke colors between your calls to vertex(). Keep in mind, that this does not seem to work with all renderers.
I'm not sure if there is a way to do it with curves.
Related discussions of manually drawing linear gradients and line-gradients using loops of points or ellipses --
Thank you benja, that's it. I was scratching my head why it didn't work, and your hint about the renderer compatibility solved it. It doesn't work with the default renderer (although I thought it's P2D?), but setting size to (x, y, P2D) makes gradial strokes possible.
Thank you very much!
For your information: It seems to work with curves as well.
Default is JAVA2D.
@ezkhimo: Really? It works with curves? I would love to see an example, so i don't have to figure it out by myself.