This does make more sense--thanks for the further elaboration. I actually took a different route for logic. The number of strokes is the key.Marno wrote: ↑Fri Dec 22, 2017 11:28 am
Your current logic for a single image is, I assume, like this…So far, so good. This will play a single image at 90 bpm for 300 beats, which will take 200 seconds (3⅓ minutes).
- Randomly choose a speed — let's say 90 bpm.
- Randomly choose a number of strokes — let's say 300 beats.
- The total time in seconds is beats × 60 ÷ bpm — in this example, 300 × 60 ÷ 90 = 200 seconds.
But, if the optional minimum and maximum times are specified, the logic would go a bit further…
- Check the minimum time. If the minimum time is more than the total time, extend the number of beats. In this example, if the minimum time is 100 seconds, ignore it; but if it's 300 seconds, the number of beats would be increased to 450 beats.
- Likewise, check the maximum time. If the maximum time is less than the total time, reduce the number of beats. In this example, if the maximum time is 300 seconds, ignore it; but if it's 150 seconds, the number of beats would be reduced to 225 beats.
- Count number of strokes
- Pick a time within bounds
- Calculate and set the timer
The application is event driven. When the timer is up, it counts down independent of anything else happening. The metronome for example is doing its own thing independent of the timer or image loader. This has strengths and weaknesses. For example, I don't have to ensure the timing is perfect for any given object, just that the metronome ends before the slide does, and provide a short fuse. Otherwise, I'd be counting seconds and looking through an event queue which is a serious PITA when things fall out of sync! JavaScript can be prone to that when too many timers are running.
What does make sense based on your explanation is to add a safety limit where regardless of settings, the game could never exceed x seconds. And, to ensure the desired effect, don't let slides fall below x seconds in length.
Thank you for the feedback. I'll digest it and see if I can't see how to implement. Cheers!