// min is green -> calculate relative red and blue steps // Analysis else if(min == "green") { steps = Math.abs(difGreen); Rsteps = difRed / Math.abs(difGreen); if(difGreen > 0) Gsteps = 1; else Gsteps = -1; Bsteps = difBlue / Math.abs(difGreen); }This section of code is conceptually the same as the previous section, except that the minimum amount is green. Similar to the previous section, steps is assigned the absolute value of the difGreen variable, and Gsteps is assigned either 1 or -1, depending upon the sign of difGreen.
Calculating the increment per step for the colour red is simply a matter of dividing difRed by the
absolute value of difGreen. The absolute value is taken to ensure that the difGreen variable doesn't
accidentally alter the sign of the Rsteps variable. If both difGreen and difRed had been negative
amounts, Rsteps would have (incorrectly) been assigned a positive increment amount.