Jump to content
Sign in to follow this  
LeGalactique

Beginner VEX Excercise Modulo

Recommended Posts

Posted (edited)

Hi all,

I am fairly new to VEX and currently on day 12 of joy of vex, I was trying to do this excercise:

"Highlight red all the points where their ptnum can be cleanly divided by 10"

Someone recommended to use modulo and I did find a way to make it work but

honestly I do not entirely understand why it works, if anyone can help me understand this better I would appreciate it.

 

I understand modulo is basically the remainder of a division and that in this case it will loop from 0,1,2,3,4,5,6,7,8,9,0 through @ptnum.

 

 

int a = @ptnum % 10 ;

if 

(@ptnum = a)

{

@Cd.r = 1;

}

else 

{

@Cd.g = 0;
@Cd.b = 0;
}

Edited by LeGalactique

Share this post


Link to post
Share on other sites
2 hours ago, LeGalactique said:

I understand modulo is basically the remainder of a division and that in this case it will loop from 0,1,2,3,4,5,6,7,8,9,0 through @ptnum.

There, you've perfectly understood what it's for.
Creating loops from continuous data is the main use of this function.

Share this post


Link to post
Share on other sites
Posted (edited)

Hey thanks! So basically when I say:

if

(@ptnum = a)  //I still don't get why this works on my first code.

I was doing things backwards? I mean I can use this to tell Houdini that

all numbers not 0 will be one color, so I should have written:

if

(@ptnum != a)

 

That was the part I didn't catch, it is all based on any number that doesn't have a remainder right?

 

Something like:

 

if

(@ptnum %10 == 0)

{

@Cd = {1,0,0};

}

Edited by LeGalactique

Share this post


Link to post
Share on other sites

All number have a remainder even if its 0.

If you want to better understand what happen make "a" an attribute and check the geometry spreadseet, you will see all the values generated.

i@a  = @ptnum % 10;
if(@a == 0)
{
    @Cd = {1,0,0};
}

Or you also can use the printf function.

Share this post


Link to post
Share on other sites
17 hours ago, flcc said:

All number have a remainder even if its 0.

If you want to better understand what happen make "a" an attribute and check the geometry spreadseet, you will see all the values generated.

i@a  = @ptnum % 10;
if(@a == 0)
{
    @Cd = {1,0,0};
}

Or you also can use the printf function.

I had done this before but still wasn't getting it, I appreciate your help alot and I think I understood now entirely.

 

What I didn't get was why if I did (@ptnum = a) then I could color all numbers from 1-9 between each 10th increase.

Since I am a beginner I was failing to understand the difference between == equal to and = asign or can be asigned.

Also I was thinking of the modulo remainder and failing to grasp how those values translated to houdini, when you

just see it as a loop and see that the loop is 1-9 then every tenth is 0 or basically nothing and that cannot be assigned

as a value to ptnum hence you can pinpoint that to add a value.

 

This is how I have come to understand it, needed to really know what happened basically.

Share this post


Link to post
Share on other sites

Cool.
But I would still suggest you to acquire some programming basics elsewhere, because VEX and the graph system adds a layer.
If you are also a beginner in coding, it will be difficult for you to determine the source of errors.
There are many sites to learn a language.
VEX is close to C, but java, or even python can do the trick to learn coding.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×