Howto do a slow for loop



if I do a for-loop like

def draw(screen, etc) :
    for X in range (0,100) :
         #do something here with X

then X is counted up each 30ms (=each frame that is drawn). Now I’d like to do a for-loop where the incrementation is done at a defined period, let’s say each second one step up. Is there any possibility?


Replying myself:

I found that I can do something like

def draw(screen, etc) :
    for XX in range (0,100 * 10) : 
         X = int(XX / 10) 
         #do something here with X

Which makes the loop ten times slower.
But I still hope for a different solution with something like “sleep”.


You cannot sleep as the render function needs to complete for every frame.
What you can do instread is count frames which you know happen at 30fps, so do a bit of your ‘work’ every N frames.

( there are other ways but this is the easiest solution)


Yepp, counting frames should be an easy thing. Thanks for the hint!

And thinking of frames: Another possibility might be relating it to MIDI clock. Then my rain would be in timing with the music too.


Yeah syncing with midi clock is easy (and similar)
You just do you work whenever you get N clock ticks, you don’t even need to count frames - unless you want it to also work when no clock is received