Got it! Sorry for the multiple posts, but I finally got this to work and figured it may be useful to someone else. The problem with the code immediately above is that the get() was returning a ridiculous negative value (not sure why -- any ideas?). Since this value was never equal to the row index, the attributes never changed.
What I did below was run red(mousecolor) to get the red value for mousecolor. This corresponds neatly to the row index, and voila -- problem solved!
The return value on get() really has me flummoxed though -- what is that enormous number that's getting passed through?
Thanks again -- going to see about getting this to work in a pjs context now...
PShape USMap;
PShape state;
PGraphics buffer;
boolean flag;
Table data;
float redint;
color c;
color buffercolor, mousecolor;
float dataMin = -7;
float dataMax = 11;
void setup() {
size(700, 500);
buffer = createGraphics(width, height, JAVA2D);
USMap = loadShape("usmap.svg");
data = new Table("random.tsv");
smooth();
flag = false;
}
void draw() {
background(255);
noStroke();
USMap.disableStyle();
int rowCount = data.getRowCount();
for (int row = 0; row < rowCount; row++) {
String abbrev = data.getRowName(row);
state = USMap.getChild(abbrev);
buffer.beginDraw();
buffer.background(255);
buffercolor = row;
buffer.noStroke();
buffer.fill(buffercolor);
buffer.shape(state, 0, 0);
buffer.endDraw();
mousecolor = buffer.get(mouseX, mouseY);
redint = red(mousecolor);
if (state == null) {
println("No state found for" + abbrev);
}
else {
float value = data.getFloat1(row, 1);
if (value >= 0) {
float amt = norm(value, 0, dataMax);
c = lerpColor(#FFFFFF, #221177, amt);
fill(c);
}
else {
float amt = norm(value, 0, dataMin);
c = lerpColor(#FFFFFF, #992211, amt);
fill(c);
}
stroke(255);
fill(c);
if (redint == row) {
fill(100,100,100);
}
shape(state, 0, 0);
}
}
println(mousecolor);
println(redint);
noLoop();
}
void mouseMoved() {
loop();
}