Hey guys !
I’m new here and I already have a question. I searched on the internet and didn’t find an answer, so I hope you’ll help please understand some things !
I created my first app, based on the tutorials, but there’s something I find weird about the draw() function.
It’s a loop function, like on Processing, Arduino, etc.
But if you create a circle in the draw function, and update it’s coordinates x and y, the circle moves.
Why doesn’t it create a new circle with the new positions ? Why does it think that it’s the same circle ?
How can I generate a new circle on every position ? Like x+10, y+10 ?
Is this about classes ? Do I have to create a general circle class and create a new object for new circles ?
Thanks for you answers, I’m trying to understand what happens inside the function.
When the draw function is done, your screen is cleared, this means in the next loop you need to draw everything again.
If you want to have several circles you should call ofCircle as many times as circles you want in the same drawing loop, and for that you need to store the positions (in a vector for instance).
This doesn’t relate to classes directly. It does not matter whether you have a circle class or not. Notice ofCircle doesn’t create circle objects, it just draws a circle.
I understand, so they are created in the first loop, but how can it create a new circle in the next loop, for example ?
Is there a way to identifie a loop ?
In fact they are never created, they are just drawn.
Keep that in mind, otherwise your approach will be wrong.
What do you want to do exactly? Do you want a known number of circles to be drawn? Or maybe keep drawing circles in the mouse position indefinitely?
Depending on what you want you might want to try different solutions.
[quote=“chuckleplant, post:4, topic:14115, full:true”]Or maybe keep drawing circles in the mouse position indefinitely?
That’s it, I want to draw circles depending on my mouse moves, like generating stars where the mouse moves, but for now it will be circles.
Probably you want to draw them on a ofFbo, check the fboTrailsExample. Or the alphaMaskingShaderExample. They both draw stuff in this Frame Buffer Object, think of it as another screen, except this one won’t get cleared unless you explicitely clear it.
You can then draw circles on click or whenever you want, and render them onto this FBO.
Thank you very much, I’ll try that !
you can also use:
in setup, and your application will behave as it would do in processing
Thank you, you both helped !