there is a way to put the single shapes into a PGraphics
and only handle that one …
so not even need the shape group anymore
https://processing.org/reference/PGraphics.html
but here a simple background shape with mouseover
PShape s1, s2, s3,shapecatch, s;
void setup() {
size (200, 200, P2D);
make_shape();
s.scale(2);
s1.setFill(color(200,0,0));
s1.setStroke(color(200,0,0));
}
void draw() {
background (200, 200, 0);
shape(s,width/2,height/2);
// the original circle was diamater 40, but because of scale(2) we need here 80
if ( overCircle(width/2,height/2,80) ) shapecatch.setFill(color(0,200,0,80));
else shapecatch.setFill(color(0,200,0,30));
}
void make_shape() {
s = createShape(GROUP);
ellipseMode(CENTER);
shapecatch = createShape(ELLIPSE, 0, 0, 40, 40);
shapecatch.setFill(color(0,200,0,50));
shapecatch.setStroke(color(200,200,0));
s1 = createShape(ELLIPSE, 0, 0, 15, 15);
s2 = createShape(TRIANGLE, -2, -6, -11, -9, -6, 0);
s3 = createShape(TRIANGLE, -2, 6, -11, 9, -6, 0);
s.addChild(shapecatch);
s.addChild(s1);
s.addChild(s2);
s.addChild(s3);
}
boolean overCircle(int x, int y, int diameter) {
float disX = x - mouseX;
float disY = y - mouseY;
if (sqrt(sq(disX) + sq(disY)) < diameter/2 ) {
return true;
} else {
return false;
}
}
but any transformation
- translate
- rotate
- shear
- scale ( used here! )
makes a mouseover very difficult.