We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey,
is there a way to get the color from a PShape object? I couldn't find an answer in the refrences and also the search didn't spit out something useful.
Thank you so much for your answers!
Answers
use get() function
http://www.processing.org/reference/PImage_get_.html
Hey, thanks for the answer but isn't the get() function only part of the PImage class? I think so because i couldn't get it work. :(
Perhaps some code is helpful? Voila, that's what i'm trying:
You should have specified it was about a PShape created from SVG...
Note that a SVG shape can be compound, so can be made of several colors. And even a primitive shape / path can have a gradient color.
Note that PShape has a fillColor field, but it is protected (not usable directly) and there is no getter for it... :-(
If fillColor is a
protected
field, it means we can access it if we inherit the class.Problem is that loadShape() is the 1 which instantiates the PShape.
And we'd need to hack it in order to force it to instantiate our modified PShape subclass! :o3
It's much worse, internal loadShape() is called upon an already instantiate PGraphics!
I believe we'd have to use reflection to reach it now then! :-SS
Wuhuu, thanks for the answers!
Well, i think the easiest way would be to parse the svg file as a xml and handle the data manually. Shouldn't be that hard.
But could you tell me where you've got the information about the fillColor field? I'm new to processing but familiar with java. Where can i find the references for the processing core?
Thank you all! :)
double post. Whenever i post something i get an error that the xml could'nt be read. :( Sorry
https://github.com/processing/processing/tree/master/core/src/processing
https://github.com/processing/processing/blob/master/core/src/processing/core/PShape.java#L158
Thank you! :-h
Before you go, I've finally succeeded in capturing PShape's fillColor field: :ar!
Wohoo awesome!
Thank you so much! This really helps a lot! :)
Hello, this post was from 2014.
I am just curious.
Why the follow example will only work if a rendered (like P2D) is chosen
PShape.getFill()
doesn't seem to be included in the reference:...I'm assuming because it isn't (consistently / completely) implemented?
Other than defining a renderer that isn't Java2D:
In general with states in Processing that don't have getters, the workaround is to save the state in a separate variable, then retrieve it later from there:
...or, if you could many create an array or arraylist of colors.
Possibly related issues about calling PShape.getFill():