We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I am writing a sketch where I must be able to load an SVG, access its children, get shape fill colors and change them on a new PShape. The new PShape would be the same as the original PShape with fill colors changed.
From what I have seen in forums and documentation, presently there is no way to duplicate a PShape, so I am loading the same SVG twice ( in = loadShape("shape.svg"); out = loadShape("shape.svg");).
After that I iterate through each in.getChild, find out the family, and if it has children, iterate again.
My problem is that I have to find out the fill color for PRIMITIVE / PATH / GEOMETRY families. The only method I can find is getFill(int index) (http://www.processing.org/reference/javadoc/core/processing/core/PShape.html#getFill(int)), but there is no documentation. I may be wrong, but it seems to me that a method getFill() with no parameters to get the fill color of the current shape would be more helpful than getFill(int Index). But then again, I may have totally missed the point of the "index" parameter.
A similar question has been asked here: http://forum.processing.org/one/topic/pshape-getfill.html
I apologize for double posting, but the question I am referring has no answers, and I really need to find a way to do this.
Thanks in advance for your help.
Answers
I might be wrong, but from my messing around, the index of 0 is the object itself and the indexes are for the vertices. On my project, I use that method for both get and set.
Hi,
Thanks for your reply. My problem is that I tried to get all the fills (getFill, index 0) for all children of the parent object and none of them returns anything. I tried with different SVG files and they show perfectly when drawn on screen, but I still don't get any value from getFill(). I think a fill color for vertices does not make sense (stroke would be more like it), but you may be right. I just haven't managed to replicate your results. Would it be to much to ask for your code? The part that finds fill colors would suffice.
Hi there,
Old question, but maybe still helpful for other people... The
Shape.getFill(int index)
function returns the fill color for the vertices, unless there are no vertices or the index is out of the vertices array bounds. If this is the case, then it returns the shape'sfillColor
:https://github.com/processing/processing/blob/89cce06b1c7fab974c1720b87e25c1af68c56b27/core/src/processing/core/PShape.java#L2356
You can use a trick to always get the
fillColor
: use a very large index number!Hope this helps ;)