I'm trying to draw a selected US state in the center of the next page. However, when I call shape(state,width/2, height/2), it draws the state relative to where it would be if the US map were centered on the screen (i.e. Washington isn't in the center of the screen, its at the top left). Any ideas o nhow to get it to draw the shape in the center of the screen?
Hey,
I've advanced in my program, but am now having the problem that certain states won't draw properly, as evidenced above (Alaska, Massachusetts, Hawaii).
Any thoughts why?
Thanks
I'm trying to make an interactive map of the US that can recognize what state the mouse is over when it clicks. To do this, I need to be able to find if mouseX and mouseY are within a state. I can figure out how to do this for any reasonable geometric shape (circle, rect, triangle, etc) but don't know how it can be done with a state. I'm using a blank SVG map of the US and I've found two things that might help but I can't figure out how to make them work. One is this code:
public boolean contains(float x, float y) {
if (family == PATH) {
boolean c = false;
for (int i = 0, j = vertexCount-1; i < vertexCount; j = i++) {
if (((vertices[i][Y] > y) != (vertices[j][Y] > y)) &&
(x <
(vertices[j][X]-vertices[i][X]) *
(y-vertices[i][Y]) /
(vertices[j][1]-vertices[i][Y]) +
vertices[i][X])) {
c = !c;
}
}
return c;
} else {
throw new IllegalArgumentException("The contains() method is only implemented for paths.");
}
}