Your code for the CF takes three variables, $J1, $Z1 and Colour, I've simply arranged a sample of these in an array, laid out as a table by using line breaks. Each "row" shows the two conditions and the resultant colour. The code loops through these in steps of 3 to insert them into the CF code, avoiding all the repeated lines.