[reactive] Bounce

Greg Fitzgerald garious at gmail.com
Thu Nov 20 22:00:18 EST 2008


Thanks Conal, this library is really looking great.

-Greg


On Thu, Nov 20, 2008 at 6:19 PM, Conal Elliott <conal at conal.net> wrote:
> Hi Greg.
>
> I'd use a couple of integrals and a snapshot, and the result would indeed be
> recursive.  I carefully designed the semantics of reactivity to make this
> sort of thing possible.  In particular, switcher switches immediately after
> event occurrences.  Not "one tick" or some such (since Reactive is based on
> continuous time), but really immediately.  Thus snapshotting a behavior at
> the moment it switches gets the pre-event-occurrence value.  This sort of
> formulation worked fine in Fran and was great fun.
>
> Now here's the temporary bad news:  Currently, there's a bug in the Reactive
> implementation, and this sort of (recursive) example locks up. :(  Creighton
> is looking into it.  http://trac.haskell.org/reactive/ticket/1 .
>
>   - Conal
>
> On Thu, Nov 20, 2008 at 5:35 PM, Greg Fitzgerald <garious at gmail.com> wrote:
>>
>> 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
>> _______________________________________________
>> Reactive mailing list
>> Reactive at haskell.org
>> http://www.haskell.org/mailman/listinfo/reactive
>
>


More information about the Reactive mailing list