We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm making an animation and would like to have a way to preview my work without having to start at the very beginning of the animation every single time. The animations don't have any user interaction and are basically just a linear set of instructions. Is there a way to calculate the state of things according to a given frameCount during compile before running?
Answers
Use another variable.
Set it to framecount at top of draw when running properly, set it to required value in setup and increment it at bottom of draw when running in debug mode.
Adding on to my original post, say I have the following code:
When I run the code, I would want to see a gray rectangle.
Well it's 35 in setup but you're checking for 30 in draw....
I'd think framecount is incremented before draw is called. There's probably nothing stopping you modifying framecount yourself, except common sense... 8)
Thanks koogs, but the animation isn't entirely driven by the frameCount value. My example was probably a bit oversimplified. The animation includes processes set in motion in the draw() function, so the following code would be more accurate:
So starting with frameCount at 80 shows the lines in the same position, but if the sketch had started with a frameCount of 0, they would show in different positions. I'd like a way to compile the sketch as if it had been started from frameCount = 0, but start playback at frameCount = 80.
I would try to become independent of the frameCount-variable. One way would be to move all the animation-code into a seperate function and call it once inside of draw. Here is an example:
As you will notice, i used the variable "progress" instead of frameCount here. The function "animation" contains everything that you would normally do inside of draw. To skip a part of the animation you can call it with the number of steps to be skipped as an argument inside of setup();
Thanks, benja! That's exactly what I was looking for.
I don't see how that helps when you've got cumulative global variables like lineAAngle
There is a simpler option: just use a
for
loop to call thedraw()
function a bunch of times at the end of thesetup()
function.Consider this little program that draws a moving circle that resets to a random position when it goes off the window:
The result of all this logic isn't directly dependent on the
frameCount
variable, but it is dependent on running thedraw()
function over and over again. So if I want to skip over the first1000
frames, I can just do that directly:Note that I'm incrementing the
frameCount
variable, but that's more a "just in case" thing. Now if I just want to start at the beginning, I can just changeSTART_FRAME
to0
and it'll skip my "fast forward"for
loop.You could simplify the loop a bit and use the
frameCount
variable directly: