Jump to content

Beginner VEX Excercise Modulo


LeGalactique

Recommended Posts

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
Link to comment
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.

Link to comment
Share on other sites

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
Link to comment
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.

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...