Elm playground: how to act at the beginning or end of an animation loop?


I’m playing around with the playground library and can’t figure something out, I think this little demo of a bouncing ball should speak for itself :


The culprit is explained at line #27, and I’m not quite sure sure how to solve registering “ceiling hits”.

I’d also like to register a change of behavior every time x crosses zero so ideally I’m looking for a generic solution.

Another way to look at this, is that I’d like to register a change of behavior at the beginning, middle or end of the wave function cycle.

I thought about accumulating x values to later apply a modulo operation but that seems too complicated as the initial x value is dependent on time plus I would have to track previous x values so I’m guessing I must be missing something obvious.

Any ideas?

1 Like

Hello, made this for you: Ellie

I introduced a flag to avoid double counting.

1 Like

Hello Hans,

Great solution, many thanks!!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.