Setup:
I am using Reactive Banana along with OpenGL and I have a gear that I want to spin. I have the following signals:
bTime :: Be
A simple approach is to assume that eDisplay
happens at regular time intervals,
and consider bAngularVelocity
to be a relative rather than absolute measure, whch would give you the really rather short solution below. [Note that this is no good if eDisplay
is out of your control, or if it fires visibly irregularly, or varies in regularity because it will cause your gear to rotate at different speeds as the interval of your eDisplay
changes. You'd need my other (longer) approach if that's the case.]
eDeltaAngle :: Event t (Double -> Double)
eDeltaAngle = (+) <$> bAngularVelocity <@ eDisplay
i.e. turn the bAngularVelocity
into an adder Event that fires when you eDisplay
, so then
eAngle :: Event t Double
eAngle = accumE 0.0 eDeltaAngle
and finally
reactimate $ (draw gears) <$> eAngle
Yes, approximating the integral as a sum is appropriate, and here I'm further approximating by making possibly slightly inaccurate assumtions about the step width, but it's clear and should be smooth as long as your eDisplay
is more-or-less regular.