[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Negative number positive



I can tell you why. I need it for mirroring. Imagine a 3D environment you are watching in ego perspective (Dungeon Master like). There is a walk way for NPCs from left to right in steps of 5 positions (0-4, each position represents a coordinate pair on which the NPC is painted). So, position 0 is the most left while position 4 is the most right on the screen.
There is now a NPC passing the way from 0 to 1 and waiting there (quite on the left border of the screen). Now you pass him crosswise, turn by 180 degrees and watch him again. Ooops he is still standing on the left side on the screen but by mirroring he should now stand on position 3 (on the right side).
I was looking for a easy way how to calculate the new position when mirroring happens. Based on my example: How do I come from 1 to 3? I use 0 are mirror and subtract 4 from 1 = -3. The negavite value is not a valid position so..... abs()
Based on my example it works for all values
0 <-> 4
1 <-> 3
2 <-> 2
3 <-> 1
4 <-> 0


Thats all about. If there is a better way, please let me know.
Farai


Am 27.12.2006 um 23:47 schrieb Luke Paireepinart:

Caleb Mahase wrote:
Farai Aschwanden wrote:
Tnx, some guys already told me in between, its abs(-x)
or just abs(x).
why would you put a negative number in front of the variable name?
that will make
negative -> positive
positive -> negative
and then the abs() function will do
negative -> positive
positive -> positive.
the negative has no meaning in this situation.
HTH,
-Luke
Farai


Am 27.12.2006 um 21:50 schrieb Caleb Mahase:

Farai Aschwanden wrote:
Hello

Erm, not a Pygame 1.8 question but just cant find the the needed function: I would like to make a negative number to a positive number, like -5 -> 5

Quite easy, just cant find the Python function (if there is one). Sure I could multiply the negative value by -1 but I would prefer using the convention function. Is there one and what is it called?

Thanks in advance
Farai
Just get the absolute value. I think its fabs() or abs().

- Cal





Yeah I just saw that! :)