# Preserving Stroke Color in PGS Library when subtracting Shapes

**URL:** <https://discourse.processing.org/t/preserving-stroke-color-in-pgs-library-when-subtracting-shapes/41612>\
**Category:** Libraries\
**Created:** [April 4, 2023, 11:30pm UTC](https://discourse.processing.org/t/preserving-stroke-color-in-pgs-library-when-subtracting-shapes/41612 "2023-04-04T23:30:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hotti](https://avatars.discourse-cdn.com/v4/letter/h/e36b37/32.png) [@hotti](https://discourse.processing.org/u/hotti)\
**Post date:** [April 4, 2023, 11:30pm UTC](https://discourse.processing.org/t/preserving-stroke-color-in-pgs-library-when-subtracting-shapes/41612/1 "2023-04-04T23:30:17Z")

</div>

Hello everyone,

I have a question about using the Processing Geometry Suite (PGS) library.

I’m working on a code that subtracts a ‘circleShape’ from a collection of lines called ‘lines’.  
When generating the ‘lines’, I assign a randomly chosen stroke color.  
I’m trying to apply ‘PGS\_ShapeBoolean.subtractMesh(lines, circleShape)’ to subtract the ‘circleShape’, but the stroke color assigned during the creation of ‘lines’ gets lost.

I’ve looked into various solutions, but I haven’t found any way to resolve this issue. Is there any way to maintain the stroke color?

```auto
import micycle.pgs.*;

int nLines = 7;
int nColors = 20;
color[] strokeColors = new color[nColors];

void setup() {
  size(800, 800);
  background(255);

  for (int i = 0; i < nColors; i++) {
    strokeColors[i] = color(random(255), random(255), random(255));
  }
}

void draw() {
  PShape lines = createShape(GROUP); 

  float step = width / float(nLines);

  for (int i = 0; i < nLines; i++) {
    float x = i * step;
    PShape lineShape = createShape();
    lineShape.beginShape();
    lineShape.stroke(color(strokeColors[i]));
    lineShape.vertex(x, 0);
    lineShape.vertex(x, height);
    lineShape.endShape();
    lines.addChild(lineShape);
  }
  
    PShape circleShape = createShape();
    circleShape = createShape(ELLIPSE, 300, 300, 400, 400);
    circleShape.setFill(255);
    circleShape.setStroke(strokeColors[int(random(nColors))]);

   PShape subtructedLines = createShape();
   subtructedLines = PGS_ShapeBoolean.subtractMesh(lines, circleShape);   
  
  shape(circleShape);
  shape(subtructedLines);
  //shape(lines);

  noLoop();
}

```

---

<div class="post-metadata">

**Author:** ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)\
**Post date:** [April 13, 2023, 1:23pm UTC](https://discourse.processing.org/t/preserving-stroke-color-in-pgs-library-when-subtracting-shapes/41612/2 "2023-04-13T13:23:26Z")

</div>

There’s not a way to maintain shape style during the operation (though the upcoming release will [support](https://github.com/micycle1/PGS/pull/75/commits/a73a5ee90fb03e65f3194808f61f686852a8c009) this).

How about assigning the same stroke colors to the output instead (each child shape of `subtructedLines`)?

---

<div class="post-metadata">

**Author:** ![hotti](https://avatars.discourse-cdn.com/v4/letter/h/e36b37/32.png) [@hotti](https://discourse.processing.org/u/hotti)\
**Post date:** [April 14, 2023, 4:31am UTC](https://discourse.processing.org/t/preserving-stroke-color-in-pgs-library-when-subtracting-shapes/41612/3 "2023-04-14T04:31:40Z")

</div>

Thanks for the reply. I’m excited to hear about the next release.  
I’ve thought about it, and it seems like the only current solution is to reassign the colors at the output stage. I’m exploring the world of PGS…
