We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, so i basically i have a convex polygon that i want to fill. In my setup() i have all the loops that generate the points inside the polygon and am using ellipse() to draw each of them in a nice pattern, then i Thread.sleep(200) to make them get draw every 200ms
but now in this implementation all the points get drawn on the canvas right after setup() is done, and they get drawn all at the same time.
the question is,** how can i draw an ellipse outside draw() immediately after calling ellipse() ?** or how can i implement this in another way?
i can post some code too if it helps
Answers
Can you show your code -- or a minimal version of your code exhibiting this problem?
Until seeing the sketch, I'm not quite sure I understand why you are using Thread at all. Setup all happens before screen drawing starts.
draw()
is called every frameRate() seconds... so why not do the gradually polygon fillin of ellipses in draw()?the thing is even if i draw them in draw() and not in setup(), it will still draw them all at the same time setup()
and then i have some nested loops in fillConvexHull():
not sure if this is what you mean :
the screen is updated only at the end of draw() (and setup()) - and only once
when you're using for-loops you'll never see a gradually growing of your scene
it's all saved behind the scene and then when done put on the screen at once
if this is your issue, you can of tackle it in different ways, basically using the fact that draw in itself approx. 60 times per second
e.g. get rid of
for(int i=0;i<vertices.size()-1;i++){
and instead just
say in draw()
at the end of draw() [not at the end of setup, since setup doesn't loop]
and before draw() [not IN draw]
int i=0;
you could just say frameRate(24); to slow things down
A runnable example is always better than fragments.
or use delay (200); although that as also disadvantages
You cannot do animation without using the draw method you don't understand the role of setup and draw methods. You can find out in the Technical FAQ discussion.
among other entries look here
https://forum.processing.org/two/discussion/8085/i-display-images-in-sequence-but-i-see-only-the-last-one-why
Please post a working sketch if you are hoping for more detailed feedback. Ideally it should be an MCVE (minimal, complete, and verifiable example). The code you have shared cannot be run.
Your paradigm for drawing is off. You seem to imagine that "fillConvexHull" will completely fill the hull.
What you might want is function calls like
...or
...or
In order to make a series of calls like that over a period of time, each time you are going to draw to the screen, and then draw differently to the screen each time, you need something like (one approach):
...so that each time you are going to draw to the screen, you draw something slightly different.
Processing actually also has a built-in called frameCount for knowing how many frames you have drawn so that you don't have to count them yourself.
Hello thanks you all your answers(too late i know:P) back then i eventually made it with another graphics engine.
The problem in processing is it whenever you make a drawing call (e.g ellipse(),line()..) they dont get drawn at this time, but they gather up all together in sequence and when draw() is done, it draws them all together.
example: You want to draw some circles, one after another with 1second delay between. the following wont work: (example 1)
it will wait for circles.length seconds and then it will draw them all at the same time.
One solution would be(as Chrisir suggested):
it will work, but however in my case i had nested loops... and its not so easy to convert a nested loop into a "draw()" loop like in the above code.
so today i was making something else and faced this problem again..luckily i found a solution this time
The other solution is to:
-have a DRAWING variable for drawing.
-make draw() method only draw whatever the DRAWING value is.
-on a different thread change DRAWING value and delay();
for the (example 1) above the code converts to this(full code):
hope that will help others with the same problem! :)