PShape GROUP weirdness

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!

might be not at your point, but
draw change draw of a shape group in setup
not makes much sense to me, i would use

PShape psg, psl, pse, pse2;

void setup() {
  size(500, 500);//, P3D);
  //background(255);
  fill(0,0,200, 70);
  stroke(0,200,0, 30);
  strokeWeight(30);
  psg = createShape(GROUP);

  psl = createShape(LINE, 0, -80, 0, 80);
  psg.addChild(psl);
  //  shape(psg, 200, 100);

  pse = createShape(ELLIPSE, 0, 0, 30, 30);
  psg.addChild(pse);
  //  shape(psg, 300, 100);

  psg.addChild(pse);   // this just adds the transparency until black
  psg.addChild(pse);
  psg.addChild(pse);
  psg.addChild(pse);
  psg.addChild(pse);
  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? */

  pse2 = createShape(ELLIPSE, 0, 80, 30, 30);
  psg.addChild(pse2);
}


void draw() {
  background(200,200,0);
  shape(psg, width/2, height/2);
}

The example was merely to demonstrate the problem. The second code example gives a succinct demonstration of how two simple shapes – a line and an ellipse – somehow seem to have their vertices intermixed when you add the same child into a group. If I’m only adding the ellipse again to the group, why is the line darker? And why do the vertices of the line and ellipse get tangled together?

shapeGroupGlitch

It’s a glitch, one that produces an interesting result. But as my first example demonstrates, it’s a glitch than produces weird and unanticipated results (as one would expect from a glitch).

when i disable the P3D ( for running on RPI RASPBIAN linux ) i see ( same on windows )

but on win7 pro SP0, 64bit, Processing 3.4 mode JAVA
see your picture BUT FLICKERING terribly
( only the snap is still picture )

so the reported weirdness is connected with using
shape group & draw modify draw from SETUP & P3D renderer.

possibly the experts might look into it.

You’re right. When I turn off the P3D renderer I get the same result.

But I require the P3D renderer, and I like the glitch, so I’ve found a way to work with it to achieve what I want.

Still, I’d like to understand what’s happening…

on your system you have that flickering and you like it???

No, I don’t have the flickering.

oh pls. what info is this without your system / OS / processing version…

processing 3.3.6 ; windows 7 professional SP1 64 bit ; NVIDIA GeForce GTX 660

1 Like