+ if (validateColor(color)) {
+ if (color.equals("black"))
+ this.color = Color.black;
+ else if (color.equals("blue"))
+ this.color = Color.blue;
+ else if (color.equals("brown"))
+ this.color = new Color(88, 41, 0);
+ else if (color.equals("green"))
+ this.color = Color.green;
+ } else {
+ throw new IllegalArgumentException("Color must be" + this.colorListToString());
+ }
+ }
+
+ /**
+ * @param color
+ * @return
+ */
+ private boolean validateColor(String color) {
+ for (String c : colorsList) {
+ if (color.equals(c)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void sortColorList() {
+ Arrays.sort(this.colorsList);
+ }
+
+ /**
+ * @param eye
+ * @return
+ */
+ public int distanceTo(Eye eye) {
+ double r_diff = this.getColor().getRed() - eye.getColor().getRed();
+ double g_diff = this.getColor().getGreen() - eye.getColor().getGreen();
+ double b_diff = this.getColor().getBlue() - eye.getColor().getBlue();
+ //See https://en.wikipedia.org/wiki/Color_difference
+ Double distance = Math.sqrt(2 * Math.pow(r_diff, 2) + 4 * Math.pow(g_diff, 2) + 3 * Math.pow(b_diff, 2));
+ return distance.intValue();