// min is red -> calculate relative green and blue steps // Analysis if(min == "red") { steps = Math.abs(difRed); if(difRed > 0) Rsteps = 1; else Rsteps = -1; Gsteps = difGreen / Math.abs(difRed); Bsteps = difBlue / Math.abs(difRed); }This section of code handles the case where min is "red". To this code, it is irrelevant how min is calculated, so long as the variable contains either "red", "green" or "blue".
The first line of code sets the value of steps to the absolute value of difRed. Because we have opted to use the least number of fade steps as possible, this code assigns that value to steps. The abs() function is used in case the difRed variable is a negative number. In the function to fade the background, it is assumed that steps is a positive number.
Because difRed has been designated as the minimum amount, its value is used to determine the number of steps for the fade. For each step, then, we know that the red value needs to change by 1 unit. The if / else conditional tests to see if difRed is greater than zero, and if it is, Rsteps is assigned the value of 1 (move 1 unit per step). Otherwise, it is assigned the value of -1 (move -1 unit per step).
The code then calculates the increment per step for both the green and blue colours (Gsteps and
Bsteps). This process is explained in the next Analysis.