We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I want to change the colors of PShapes dynamically. But using 2 different threads (with different colorModes) I get interferences between the coloring of one java2D and one P3D thread. (pictures flickering and seem to be influenced by the settings in the other thread.
One problem seems to be the setting of the colormode for PShape: in the processing and javadocs I found no information about how to set it. There is the method: public void colorMode(int mode, float maxX, float maxY, float maxZ, float maxA) If I understood right the variable "mode" sets the colorMode (RGB or Hue). But which value I have to set for this?
Answers
https://Processing.org/reference/PShape.html
thanks a lot GoToLoop. I tried to invoke colorMode() e.g. having a PShape s in the second thread. Then invoking inside draw() s.colorMode(). But what is the argument for HSB mode? In the reference there is given an "int mode" I tried different values: 0, 1, 2 but without success. But if I write instead just colorMode(HSB, 255); then the image of the second thread is ok but on the cost of flickering and influencing the first one :-(?
Read the actual web reference for colorMode():
https://Processing.org/reference/colorMode_.html
yes I read this some times. And I write before I set e.g. the background colorMode(RGB, 255); and then bakcground(0); but it still looks like a thunderstorm means the backgorund changes its colour in a flickering manner. At the same time in the second thread all is quite and the background is constant background(0); ? I do not change background colours in both threads.
My experience w/ PShape is almost nil. And discussing w/o some running example won't get us anywhere. Sorry I dunno what else I can do. :(
If possible please post an MCVE that briefly demonstrates what you are trying to accomplish, and the problem. Format code with CTRL-O.
thanks goToLoop and jeremydouglass for your answers. problem is that my code contains more than 20 classes and several thousand lines of code and there is a communication with another Audio IDE as well. So I tried to reduce the code to a small sketch but till now I could not recreate the wrong behaviour. But I will try to accomplish this.
If you would not recreate the wrong behavior (hooray!), maybe you should start with your base small sketch and start migrating your 20 classes over to it until the problem is re-introduced? If the problem isn't reintroduced, you've solved your problem!
yes I will do so but in the opposite direction: taking apart functions and classes would be easier and possibly faster to handle because of the somewhat labyrinthic dependencies.
@gerome Good luck with refactoring -- let the forum know if you narrow it down to a problem area and have questions....
I reduced the code and deleted several thousend lines:
There are 2 threads and windows: one 2D (mainApplet) and one 3D (second Applet).
I have a PShape sFrame wrapped with the StrFrame class which consists of several child PShapes s wrapped in the Str class. And the colours of the PShapes s are actualized in Str.setColor() which is called by StrFrame.setColor during draw in SecondApplet.displayStrFrames().
Problem is that the setting of Colours in the PShapes seems to influence the colouring of the main Applet (2D thread): in irregular intervals the monitor of the 2D thread is flickering, sometimes you have to wait several seconds, sometimes it is more dense.
to the Code given upstairs: I have a PShape sFrame wrapped with the StrFrame class which consists of several child PShapes s wrapped in the Str class. And the colours of the PShapes s are actualized in Str.setColor() which is called by StrFrame.setColor during draw in SecondApplet.displayStrFrames().
It's too big! It'd help a lil' bit if you hit CTRL+T inside the PDE to format the code better. 8-|
In Java, the class some member belongs to, that is, its context, is determined where it is typed in within the code.
You've got 2 classes derived from Processing's PApplet: the top 1, which all sketches got, and SecondApplet.
All Processing API's accesses done outside SecondApplet, w/o using the dot
.
operator, belong to the top main PApplet.For example, when you call colorMode() @ line #296, inside class StrFrame, it's modifying the top main sketch, given it's not using the dot
.
operator.The same pattern goes to your 2 calls to method color() @ lines #224 & #248.
Both calls are relying on the colorMode() defined for the top main sketch, not your SecondApplet's colorMode().
If you need to specify which of those 2 PApplet instances it's referring to, you have to use the dot
.
operator.Again, if you want the color() from SecondApplet's instance, use your global variable sa instead:
strColor = color(strHue, strSat, strBright, strAlpha); // using color() from main sketch.
strColor = sa.color(strHue, strSat, strBright, strAlpha); // using color() from SecondApplet sketch.
strColor = p.color(strHue, strSat, strBright, strAlpha); // using color() from the PApplet passed to Str's constructor.
I forgot the right formatting, please excuse my negligence!
GoToLoop, you put the finger on the very right place: line 248, 224 resp. (if I do not call line 248 by commenting out line 142 the problem disappears) But if I put the "sa." or "p." before the color as you did in your examples I get an error message: "unexpected token: ." and the programm doesn´t start.
...here is the Code given upstairs auto formatted:
the following test sketch shows the problem but in short: if I say
colorTetra = p.color(100,100,100, 100);
I get the same error "unexpected token: ."So how can I make the color() belonging to SecondApplet's instance? :-??
I know that I cannot expect that this question will be answered but as I need to solve this problem next week I would appreciate a hint very much. [-O<
You really need to learn to make an MCVE. The reason it is hard for others to help you debug is the same reason it is hard for you to debug. Just create a simple sketch with a simple tetra, and add it. Does it compile? No? Why not?
Now go from there. I'm no PApplet expert, but working out problems with a sketc this size, you might also be able to get a bit more forum help. Clearly, when you call p.color it isn't expecting p to have any properties or methods at all. That indicates p isn't the object you think it is, and something fundamental may have gone wrong.
thanks jeremydouglass for your answer and sorry for my late reaction and cryptical code postings! I was working to make the sketch run with full power and dicided finally to let the "color" away. Even if I make Tetra static I cannot access the color function related to the specified PApplet.
I will regard the MCVE standard in future.
@gerome -- glad that you got it working by dropping color. Good luck with the project!