Finding the difference between two decimal values is simply a matter of subtracting the two. It probably isn't really necessary to write and test this code beforehand.

The main consideration here is how this section of code is going to interface with the other sections of code. More specifically, it has to be determined whether the dif variables will represent the distance between the two values (always a positive number), or the difference between the two values (sometimes negative).

In this case, the values will be represented as the difference between the two values. Later in the code, the size of the steps between each value is going to be calculated. For example, if the decimal RBG value is 200, 0, 0, and we want to fade to 0, 0, 100, there are going to be 100 steps between the two colours, and the for each step, the red value is going to decrease by 2, the green value will remain constant, and the blue value will increase by 1. Because we need to determine whether to increment or decrement each colour, we will represent the information as the difference, and not the distance, between the two values.

Close Window