Difference between revisions of "JoyOfVex5"

From cgwiki
(Created page with "=== Modulo === Everyone understands + - * /, but % usually surprises people who haven't done much coding before. % is modulo. When you first learn to divide in primary schoo...")
 
m (MattEstela moved page JoyOf Vex5 to JoyOfVex5)
(No difference)

Revision as of 15:05, 9 February 2018

Modulo

Everyone understands + - * /, but % usually surprises people who haven't done much coding before.

% is modulo. When you first learn to divide in primary school, and you do remainders, well, modulo is the remainder. That's it.

Ask a 10 year old kid '5 divided by 2' , they'll tell you '2, remainder 1'. In the same way, 5 % 2 = 1.

This is useful because it sets up loops; when the first and second number are the same, the remainder is 0. If you're doing modulo by 5 on an input that smoothly increases, like @ptnum or @Frame, you'll get a sawtooth waveform that goes 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4...

@P.y = @ptnum % 5;

Modulo works on fractional values too, so you can give it a float input, and smoothly varying float input like @Time, you still get a sawtooth pattern:

@Cd.r = @Time % 0.2;

Lots of effects involve setting up loops, modulo gives you an easy way to setup inputs or outputs that loop.

Excercises:

  1. stuff