# PShape GROUP weirdness

**URL:** https://discourse.processing.org/t/pshape-group-weirdness/7462
**Category:** Coding Questions
**Created:** [January 13, 2019, 1:38am UTC](https://discourse.processing.org/t/pshape-group-weirdness/7462 "2019-01-13T01:38:41Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Aleksi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/aleksi/32/11065_2.png) [@Aleksi](https://discourse.processing.org/u/Aleksi)
#### Post date: [January 13, 2019, 1:38am UTC](https://discourse.processing.org/t/pshape-group-weirdness/7462/1 "2019-01-13T01:38:42Z")

</div>

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.

```auto
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?

```auto
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!

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [January 13, 2019, 2:37am UTC](https://discourse.processing.org/t/pshape-group-weirdness/7462/2 "2019-01-13T02:37:00Z")

</div>

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

```auto
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);
}

```

---

<div class="post-metadata">

### Author: ![Aleksi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/aleksi/32/11065_2.png) [@Aleksi](https://discourse.processing.org/u/Aleksi)
#### Post date: [January 13, 2019, 6:45pm UTC](https://discourse.processing.org/t/pshape-group-weirdness/7462/3 "2019-01-13T18:45:10Z")

</div>

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](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/1ae3c41a2aa6c52e455b8d8403abcffe5c90f15d.jpeg)

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).

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [January 14, 2019, 2:09am UTC](https://discourse.processing.org/t/pshape-group-weirdness/7462/4 "2019-01-14T02:09:00Z")

</div>

> [@Aleksi](#):
>
> The second code example

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

 ![2019-01-14_08-57-49_snap](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/29aee313ea3a4ca8987204c6ea3adf6a27b242ed.png)

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

 ![snap_0020](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/565f92e66bd1274fe25298991fb9e1022d0e7b24.jpeg)

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

possibly the experts might look into it.

---

<div class="post-metadata">

### Author: ![Aleksi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/aleksi/32/11065_2.png) [@Aleksi](https://discourse.processing.org/u/Aleksi)
#### Post date: [January 14, 2019, 1:11pm UTC](https://discourse.processing.org/t/pshape-group-weirdness/7462/5 "2019-01-14T13:11:10Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [January 14, 2019, 1:29pm UTC](https://discourse.processing.org/t/pshape-group-weirdness/7462/6 "2019-01-14T13:29:54Z")

</div>

> [@Aleksi](#):
>
> and I like the glitch, so I’ve found a way to work with it to achieve what I want.

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

---

<div class="post-metadata">

### Author: ![Aleksi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/aleksi/32/11065_2.png) [@Aleksi](https://discourse.processing.org/u/Aleksi)
#### Post date: [January 14, 2019, 1:35pm UTC](https://discourse.processing.org/t/pshape-group-weirdness/7462/7 "2019-01-14T13:35:05Z")

</div>

No, I don’t have the flickering.

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [January 14, 2019, 1:36pm UTC](https://discourse.processing.org/t/pshape-group-weirdness/7462/8 "2019-01-14T13:36:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Aleksi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/aleksi/32/11065_2.png) [@Aleksi](https://discourse.processing.org/u/Aleksi)
#### Post date: [January 14, 2019, 1:41pm UTC](https://discourse.processing.org/t/pshape-group-weirdness/7462/9 "2019-01-14T13:41:31Z")

</div>

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