Re: [Haskell-cafe] Netwire bouncing ball

2013-07-11 Thread Ertugrul Söylemez
Just  wrote:

> Thank you very much, this works as expected and is easy to understand.
> However a complete example of a bouncing ball would be super awesome
> since I have trouble to get it work with integralLim_.
>
> My first try was to use object_ from Control.Wire.Prefab.Move but got
> stuck very quickly.

object_ is a generalization of integralLim_.  It pretty much allows you
to encode any moving behavior you want.  In general I recommend going
with the integral* wires as far as possible.


> I think this would be a good addition to the quickstart tutorial.

Thanks for your feedback.  I should write a complete example application
in the next revision.


Greets,
Ertugrul

-- 
Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.


signature.asc
Description: PGP signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Netwire bouncing ball

2013-07-11 Thread Oliver Charles
On 07/11/2013 05:52 PM, Just wrote:
> On 07/10/2013 11:44 PM, Ertugrul Söylemez wrote:
>> A very simple way to do this is to use integralLim_ instead of
>> integral_.  It allows the ball itself to handle the bouncing.  A less
>> invasive way (i.e. you can add it to your example) is to use the (-->)
>> combinator:
>>
>>  ball = integral_ 0 . integral_ 40 . (-9.8)
>>
>>  aboveGround = require (>= 0)
>>
>>  bouncingBall = aboveGround . ball --> bouncingBall
>>
>> While this gives you a bouncing ball, the ball will not follow real
>> physics.  Once the ball hits the ground, it will just start over with
>> its original velocity.  integralLim_ is the correct solution.
> 
> Thank you very much, this works as expected and is easy to understand.
> However a complete example of a bouncing ball would be super awesome
> since I have trouble to get it work with integralLim_.
> 
> My first try was to use object_ from Control.Wire.Prefab.Move but got
> stuck very quickly.
> 
> I think this would be a good addition to the quickstart tutorial.

It would indeed be a fantastic addition - this is almost exactly what I
was trying to do as my example netwire project. For a bit more support,
I was trying to move a point from x=0 to x=10, and then back to x=0 -
and so on. I got as far as getting to x=10, but then had no idea how to
reverse the direction and make the whole thing cycle. I was told to read
about ArrowLoop, but sadly I never got much further.

- ollie



signature.asc
Description: OpenPGP digital signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Netwire bouncing ball

2013-07-11 Thread Just

On 07/10/2013 11:44 PM, Ertugrul Söylemez wrote:

A very simple way to do this is to use integralLim_ instead of
integral_.  It allows the ball itself to handle the bouncing.  A less
invasive way (i.e. you can add it to your example) is to use the (-->)
combinator:

 ball = integral_ 0 . integral_ 40 . (-9.8)

 aboveGround = require (>= 0)

 bouncingBall = aboveGround . ball --> bouncingBall

While this gives you a bouncing ball, the ball will not follow real
physics.  Once the ball hits the ground, it will just start over with
its original velocity.  integralLim_ is the correct solution.


Thank you very much, this works as expected and is easy to understand.
However a complete example of a bouncing ball would be super awesome 
since I have trouble to get it work with integralLim_.


My first try was to use object_ from Control.Wire.Prefab.Move but got 
stuck very quickly.


I think this would be a good addition to the quickstart tutorial.





___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Netwire bouncing ball

2013-07-10 Thread Ertugrul Söylemez
Just  wrote:

> I'm trying to get a grasp of netwire by implementing a bouncing ball
> simulation and I'm failing.
> The ball starts from the ground with a given velocity and when hitting
> the ground the wire inhibits successfully. Now I'm kinda stuck.
>
> How can I make the ball bounce?

A very simple way to do this is to use integralLim_ instead of
integral_.  It allows the ball itself to handle the bouncing.  A less
invasive way (i.e. you can add it to your example) is to use the (-->)
combinator:

ball = integral_ 0 . integral_ 40 . (-9.8)

aboveGround = require (>= 0)

bouncingBall = aboveGround . ball --> bouncingBall

While this gives you a bouncing ball, the ball will not follow real
physics.  Once the ball hits the ground, it will just start over with
its original velocity.  integralLim_ is the correct solution.


Greets,
Ertugrul

-- 
Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.


signature.asc
Description: PGP signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Netwire bouncing ball

2013-07-10 Thread Jason Dagit
On Wed, Jul 10, 2013 at 2:15 PM, Just  wrote:
> Hello,
>
> I'm trying to get a grasp of netwire by implementing a bouncing ball
> simulation and I'm failing.
> The ball starts from the ground with a given velocity and when hitting the
> ground the wire inhibits successfully. Now I'm kinda stuck.

I've never used netwire (although I've used yampa and
recative-banana), so I can't give you help with the code, but maybe I
can help with the concepts.

I think I see what is wrong. You need to keep applying forces to the
ball. Right now, the code says, once the ball falls below a certain
point, stop applying the force (eg., clamp the output of the
integral). Instead, you could apply an upward force at the point of
impact. You can get this from newton's third law (equal and opposite
reaction). The easiest way to see a bounce would be to simply negate
the velocity when you detect a collision with the ground. A more
accurate way might involve some calculations to figure out the
impulse, but then you'll need more things like the mass of the ball.

I hope that helps,
Jason

>
> How can I make the ball bounce?
>
>
> Here is the code:
>
> {-# LANGUAGE Arrows #-}
>
> module Main where
>
> import Control.Wire
> import Prelude hiding ((.), id)
> import Control.Concurrent
>
> type Pos = Double
> type Vel = Double
> type ObjState = (Pos, Vel)
>
> testApp :: Pos -> Vel -> WireP () ObjState
> testApp p0 v0 = proc _ -> do
> v <- integral_ v0 -< -9.81
> p <- integral1_ p0 -< v
> when (>= 0) -< p
> returnA -< (p, v)
>
> main :: IO ()
> main = loop' (testApp 0 30) clockSession
> where
> loop' w' session' = do
> threadDelay 100
> (mx, w, session) <- stepSessionP w' session' ()
> case mx of
> Left ex -> putStrLn ("Inhibited: " ++ show ex)
> Right x -> putStrLn ("Produced: " ++ show x)
> loop' w session
>
> Thanks in advance!
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe