We are about to switch to a new forum software. Until then we have removed the registration on this forum.
My objective is that when you put the valor it'll draw the function "flor" but, it don't erase the last one that was drawn. How could i do that?
Answers
Copy the code and paste it here, don't expect us to try and type it all into our own computers. Also, remember to format your code.
Was trying to know how i can put the code here with the lines, i'm not that good with foruns
Format your code.
Press the gear icon to edit your post.
Select your code and press ctrl + o.
Leave a line above and below the code.
Done, sorry for trouble
Ok, good.
Rest remains same.
Well, that was simply, thank you!! Didn't even thought about that.
If ok() is called back by ControlP5, there's a risk it's under a different Thread.
If that is so, we can't directly "draw" anything to sketch's main "canvas" from there! :-O
Place
println(Thread.currentThread());
inside ok() and check its output.If it isn't "Thread[Animation Thread,5,main]", ok() is indeed being run under a "foreign" Thread and "drawing" from there may crash the sketch! =;
@GoToLoop If that is so, ControlP5 doesn't follow Processing's recommendations, and instead of using Processing's
mousePressed()
functions, it gets the mouse/key events directly from the JVM. I wouldn't see why a library aimed at beginners would allow such a major problem/flaw to exist. Most beginners wouldn't understand what Threads etc are. No, I believe that the author(s) of ControlP5 would've thought of that much. At the very least, they should've ensured that the functions associated with the different ControlP5 elements would trigger only when it is safe to draw.I don't think there's any Processing recommendations for 3rd-party libraries but only tips to make them available thru' "Contribution Manager".
I dunno about ControlP5, but many other libraries, especially those hardware-related, create their own Thread; such as Serial, Movie, etc.
Probably ControlP5 preferred to hook itself to Processing's via registerMethod() instead.
If that's the case, they're executed under sketch's own "Animation Thread". And thus it's safe to "draw".
But just to make sure it is indeed the case, I've advised about checking callbacks out via
println(Thread.currentThread());
. :-\"So none of us really knows what ControlP5 decided.
Of course Serial and Movie decided to use their own thread, Serial doesn't qualify as "beginner", and not using a seperate thread for Movie would lead to great performance losses.