I stumbled upon a really nice effect by accident duplicating shapes inside a PShape GROUP
. But when I tried to control it I discovered that I can’t because of some weirdness I can’t work around.
I figured that each new shape added to the group just adds a new pointer to the array. If I’m adding the same shape to the group, I figured it would just add another pointer to the same location. But I discovered that this doesn’t seem to be the case: sometimes shapes just disappear, or duplicate the pointer to other shapes.
Here’s one bit of code that shows the effect.
void setup(){
size(600, 200, P3D);
background(255);
fill(0, 0);
stroke(0, 30);
strokeWeight(30);
PShape psg = createShape(GROUP);
PShape ps = createShape(ELLIPSE, 0, 0, 30, 30);
psg.addChild(ps);
shape(psg, 50, 100);
psg.addChild(ps);
shape(psg, 150, 100);
// uncomment this to see additional weirdness
//psg.addChild(ps);
//shape(psg, 250, 100);
PShape ps2 = createShape(ELLIPSE, 0, 50, 30, 30);
psg.addChild(ps2);
shape(psg, 350, 100);
psg.addChild(ps2);
shape(psg, 450, 100);
psg.addChild(ps2);
shape(psg, 550, 100);
}
Here’s one that shows another effect: adding the same ellipse again glitches both the ellipse & the line. Why? Shouldn’t it just darken the ellipse?
void setup(){
size(600, 200, P3D);
background(255);
fill(0, 0);
stroke(0, 30);
strokeWeight(30);
PShape psg = createShape(GROUP);
PShape psl = createShape(LINE, 0, -80, 0, 80);
psg.addChild(psl);
shape(psg, 200, 100);
PShape pse = createShape(ELLIPSE, 0, 0, 30, 30);
psg.addChild(pse);
shape(psg, 300, 100);
psg.addChild(pse);
shape(psg, 400, 100);
/* commenting the above and uncommenting this fixes it... but why should I need to create a new shape? */
/*
PShape pse2 = createShape(ELLIPSE, 0, 0, 30, 30);
psg.addChild(pse2);
shape(psg, 400, 100);
*/
}
The effect I get from duplicating a shape in a GROUP is quite desirable in some cases, but if it’s a glitch I can’t control it, which is quite unfortunate. But since I’m able to reproduce the glitch exactly the same each time the code is executed, there must be something in the algorithm that functions in some kind of (un)planned way.
Any insight appreciated!