Expression question
11137 5 0- shihhao
- Member
- 2 posts
- Joined: Sept. 2012
- Offline
- graham
- Member
- 1904 posts
- Joined: Nov. 2006
- Online
- davidave
- Member
- 55 posts
- Joined: July 2005
- Offline
Hello, graham!
Can you explain what this expression means or do for shihhao's question? I am reading it as….when current frame # modulus 2 equals to 0, which I don't understand what it would return to tell if it's even number or odd number. Do we need another expression to tell when == 1?
Thanks and sorry for my newbie question…
David
Can you explain what this expression means or do for shihhao's question? I am reading it as….when current frame # modulus 2 equals to 0, which I don't understand what it would return to tell if it's even number or odd number. Do we need another expression to tell when == 1?
Thanks and sorry for my newbie question…
David
- animatrix_
- Member
- 4500 posts
- Joined: Feb. 2012
- Online
Hi,
Modulus returns the remainder, so the remainder of any even integer divided by 2 is 0. If it's odd, then it would be 1.
Modulus returns the remainder, so the remainder of any even integer divided by 2 is 0. If it's odd, then it would be 1.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
- davidave
- Member
- 55 posts
- Joined: July 2005
- Offline
Thanks, pusat!
After some thinking, I am not sure of something still so I hope you can help me to get the concept right.
Since the original poster's example was “return to a value of 1 when an even number is present. For example, at frame 3 it will give me a value of 0” so I am confused…
With the example and $F % 2 == 0, I am thinking
at frame 2, the remainder is 0 so the value returns 1
at frame 3, the remainder is 1 so the value returns 0
at frame 4, the remainder is 0 so the value returns 1
at frame 5, the remainder is 1 so the value returns 0
at frame 6, the remainder is 0 so the value returns 1
……….etc. (am I on right direction?)
I assume $F % 2 == 0 is just a part of the whole lengthy expression so there must be somewhere that we need to define to let it return either 0 or 1, right?
Thanks,
After some thinking, I am not sure of something still so I hope you can help me to get the concept right.
Since the original poster's example was “return to a value of 1 when an even number is present. For example, at frame 3 it will give me a value of 0” so I am confused…
With the example and $F % 2 == 0, I am thinking
at frame 2, the remainder is 0 so the value returns 1
at frame 3, the remainder is 1 so the value returns 0
at frame 4, the remainder is 0 so the value returns 1
at frame 5, the remainder is 1 so the value returns 0
at frame 6, the remainder is 0 so the value returns 1
……….etc. (am I on right direction?)
I assume $F % 2 == 0 is just a part of the whole lengthy expression so there must be somewhere that we need to define to let it return either 0 or 1, right?
Thanks,
- animatrix_
- Member
- 4500 posts
- Joined: Feb. 2012
- Online
Yes, the expression would still be simple. Just add 1 before the modulus operation:
($F + 1) % 2
You can also do it with the ternary operator (if else) but that would be slower since it has to test for the condition every time.
($F + 1) % 2
You can also do it with the ternary operator (if else) but that would be slower since it has to test for the condition every time.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
-
- Quick Links