Page 221 - The Definitive Guide to Building Java Robots
P. 221
Preston_5564C06.fm Page 202 Friday, September 23, 2005 5:13 AM
202 CHAPTER 6 ■ VISION
if (out > 255)
out = 255;
if (out < 0)
out = 0;
return out;
}
public String toString() {
StringBuffer out = new StringBuffer("ColorGram = {\n");
for (int x = 0; x < colorGram.length; x++) {
out.append(colorGram[x]);
if ((x % 4) == 3) {
if (x == colorGram.length) {
out.append("\n");
} else {
out.append(",\n");
}
} else {
out.append(",");
}
}
out.append("}");
return out.toString();
}
public boolean isMatch(Color c) {
boolean hit = false;
int count = 0;
// eliminate black since it's 0
if (c.getRed() > getRedMin(c) && c.getRed() <= getRedMax(c)) {
count++;
}
if (c.getGreen() > getGreenMin(c) && c.getGreen() <= getGreenMax(c)) {
count++;
}
if (c.getBlue() > getBlueMin(c) && c.getBlue() <= getBlueMax(c)) {
count++;
}
if (count > 2) {
hit = true;
}
return hit;
}