wrap() help?

5 views
Skip to first unread message

Kenneth M

unread,
Dec 30, 2009, 12:17:10 AM12/30/09
to Rabbyt
Hello I'm having trouble understanding the wrap() function.
Particularly collision.py, or http://paste.pocoo.org/show/160517/
Could someone please explain this code, or at least wrap()?
The docs don't tell you how this could be useful. :|

Matthew Marshall

unread,
Dec 30, 2009, 10:09:10 PM12/30/09
to Rabbyt
On Dec 29, 11:17 pm, Kenneth M <kennethm...@gmail.com> wrote:
> Hello I'm having trouble understanding the wrap() function.
> Particularly collision.py, orhttp://paste.pocoo.org/show/160517/

> Could someone please explain this code, or at least wrap()?
> The docs don't tell you how this could be useful. :|

It keeps an anim (the second) within a given boundary... which
probably doesn't make things any clearer for you.

Notice how `wrap` is used in the link you sent: (reformatted to see
the arguments easier, and I took out the rand stuff)

s.x = wrap(
[-400,400],
lerp(0, 400, dt=4, extend="extrapolate")
)

The lerp goes on infinitely. If you assigned the lerp directly to
s.x, the sprites would go off the the screen after four seconds.
Using wrap makes them wrap around to the other side.

Wrapping with the bounds [0, 400] converts the value like this:

20 => 20
400 => 400
401 => 1
430 => 30
810 => 10
-1 => 399

Hope that makes sense now :-)

MWM

Kenneth M

unread,
Dec 31, 2009, 12:21:48 AM12/31/09
to Rabbyt
So wrap() makes sure that the sprites do not go off of the screen?

On Dec 30, 7:09 pm, Matthew Marshall <matt...@matthewmarshall.org>
wrote:

Reply all
Reply to author
Forward
0 new messages