[reactive] Bounce
Greg Fitzgerald
garious at gmail.com
Thu Nov 20 20:35:39 EST 2008
How do I make a Behavior of a bouncing motion? I want to reverse the
velocity when the object goes beyond a certain position, but since the
position depends on the velocity, I have a loop. Is there a way to
make recursive behaviors, or am I going about this all wrong?
bouncingPosition :: Behavior Double
bouncingPosition = ???
bouncingVelocity :: Double -> Behavior TimeT -> Behavior Double
bouncingVelocity v0 t = velocityB v0 t `switcher` ???
collision :: Event a -> Behavior Double -> Event Double
collision e = once . filterMP (< -2) . snapshot_ e
positionB :: Double -> Behavior Double -> Behavior Double -> Behavior Double
positionB x0 v t = (x0 +) <$> liftA2 (*) v t
velocityB :: Double -> Behavior Double -> Behavior Double
velocityB v0 t = velocity v0 <$> t
velocity :: Double -> TimeT -> Double
velocity v0 t = v0 - 9.8 * t
Thanks,
Greg
More information about the Reactive
mailing list