# Set PShape parameters

**URL:** <https://discourse.processing.org/t/set-pshape-parameters/21556>\
**Category:** Processing\
**Created:** [June 4, 2020, 12:34pm UTC](https://discourse.processing.org/t/set-pshape-parameters/21556 "2020-06-04T12:34:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Moritz](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Moritz](https://discourse.processing.org/u/Moritz)\
**Post date:** [June 4, 2020, 12:34pm UTC](https://discourse.processing.org/t/set-pshape-parameters/21556/1 "2020-06-04T12:34:27Z")

</div>

Hello,  
I want to set the parameters of a PShape without creating a new one. Is it possible or do i have to create a new Pshape? thank you

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 4, 2020, 12:52pm UTC](https://discourse.processing.org/t/set-pshape-parameters/21556/2 "2020-06-04T12:52:21Z")

</div>

see [https://www.processing.org/reference/PShape\_setVertex\_.html](https://www.processing.org/reference/PShape_setVertex_.html)

(see [https://www.processing.org/reference/PShape.html](https://www.processing.org/reference/PShape.html) )

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 4, 2020, 1:13pm UTC](https://discourse.processing.org/t/set-pshape-parameters/21556/3 "2020-06-04T13:13:13Z")

</div>

```auto

ArrayList<VertexMover> list = new ArrayList(); 
PShape s;

void setup() {
  size(400, 400);
  background(110);

  fill(255, 0, 0);
  stroke(0); 
  s = createShape();

  s.beginShape();
  s.vertex(random(10), random(0));
  PVector v = s.getVertex(0);
  list.add(new VertexMover(v)); 
  s.vertex(random(50, 60), random(10));
  v = s.getVertex(1);
  list.add(new VertexMover(v));
  s.vertex(random(50, 60), random(50, 60));
  v = s.getVertex(2);
  list.add(new VertexMover(v));
  s.vertex(random(10), random(50, 60));
  v = s.getVertex(3);
  list.add(new VertexMover(v));

  s.endShape(CLOSE);
}

void draw() {
  background(110);

  for (int i = 0; i < s.getVertexCount(); i++) {
    list.get(i).move(); 
    s.setVertex(i, list.get(i).pv.copy());
  }

  shape(s);
}

// =========================================================================

class VertexMover {
  PVector pv; 
  PVector mov;

  //constr 
  VertexMover(PVector pv_) {
    pv=pv_.copy();

    mov=new PVector(random(.7, 3), random(.7, 3));
    if (random(100) > 50) 
      mov.x*=-1;
    if (random(100) > 50) 
      mov.y*=-1;
  }//constr 

  void move() {
    pv.add(mov);

    if (pv.x>width) mov.x=-abs(mov.x);
    if (pv.x<0) mov.x=abs(mov.x);

    if (pv.y>height) mov.y = -abs(mov.y);
    if (pv.y<0) mov.y = abs(mov.y);
  }//method
  //
}//class
//

```

---

<div class="post-metadata">

**Author:** ![Moritz](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Moritz](https://discourse.processing.org/u/Moritz)\
**Post date:** [June 4, 2020, 2:17pm UTC](https://discourse.processing.org/t/set-pshape-parameters/21556/4 "2020-06-04T14:17:36Z")

</div>

```auto
size(1000, 1000);
PShape s1 = createShape(RECT, 300, 300, 100, 100);
PShape s = createShape(GROUP);
s.addChild(s1);
//this doesn't work
s1 = createShape(RECT, 600, 600, 50, 50);
//so i have to change the parameter of s1
shape(s);

```

but i can’t find a way ay [https://github.com/processing/processing/blob/master/core/src/processing/core/PShape.java](https://github.com/processing/processing/blob/master/core/src/processing/core/PShape.java)

Is it possible to do that?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 4, 2020, 3:39pm UTC](https://discourse.processing.org/t/set-pshape-parameters/21556/5 "2020-06-04T15:39:56Z")

</div>

Basically when you have s1

s1 is child

Change s1 vertex as I did above

Treat s1 like it were the main shape

Change the position of the vertex of s1 like in my example

---

<div class="post-metadata">

**Author:** ![Moritz](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Moritz](https://discourse.processing.org/u/Moritz)\
**Post date:** [June 4, 2020, 4:12pm UTC](https://discourse.processing.org/t/set-pshape-parameters/21556/6 "2020-06-04T16:12:15Z")

</div>

[https://processing.org/reference/PShape\_setVertex\_.html](https://processing.org/reference/PShape_setVertex_.html)…  
description - last sentence… It’s not working…

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 4, 2020, 4:14pm UTC](https://discourse.processing.org/t/set-pshape-parameters/21556/7 "2020-06-04T16:14:43Z")

</div>

Didn’t know

What about redefining, add again and remove old version of child shape?

There is a longer doc online - link on the site you posted

---

<div class="post-metadata">

**Author:** ![Moritz](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Moritz](https://discourse.processing.org/u/Moritz)\
**Post date:** [June 4, 2020, 4:18pm UTC](https://discourse.processing.org/t/set-pshape-parameters/21556/8 "2020-06-04T16:18:55Z")

</div>

That would work, but would be too difficult to implement. I have found a way to work around the problem. It looks hopeless… Thank you anyway.
