Blog > 0-1

The 0-1 range

 So... math, right? I think 0 and 1 are some pretty cool numbers.

Multiplication!

 For me, most of the use of the [0, 1] range comes from multiplying numbers within it. 0 and 1 are already great since you can either leave a value alone or completely nullify it, but multiplying with stuff like 0.382? That's when things get interesting-er.

 In the context of shaders, you can make masks this way- the color of a given pixel is represented by 3 channels: R, G and B. Each is a value between 0 and 1. Say you multiply a random image with a completely gray one. Gray is (0.5, 0.5, 0.5), which means you halve each color channel's value and effectively darken all pixels in the original image.
 This is actually a "blend mode" in photo editing software literally called "multiply", by the way! There's many blend modes, some being more complex, but this is one that either changes nothing or darkens the image.

Percentages!

Spoiler: this is still about multiplication.
 Percentages are great too- want to calculate how far along a progress bar should be drawn? Just take the amount of things currently loaded and divide it by the total amount. Though we multiply them with 100 so they look nice, the actual values we use when working with percentages are still from 0 to 1 (aka 0% to 100%).

In programming!

 I sometimes use nothing but numbers for certain things instead of if statements. If statements can be slow, and are a binary "execute or don't execute" compared to numbers which, when used wisely, can lead to more complex behaviour. Think of how xp orbs float towards you in minecraft. They could just start floating once you're x blocks away at maximum speed... OR start floating but with their speed multiplied by a value that gets higher the closee you are. I'm guessing that value is (max distance - distance) / max distance, e.g the player has to be 4 blocks away max and their current distance is 2, so (4 - 2) / 4 = 0.5

0.50 • 0.50 = 0.250