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
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
//
1 Like
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
Is it possible to do that?
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
1 Like
https://processing.org/reference/PShape_setVertex_.html…
description - last sentence… It’s not working…
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
1 Like
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.
1 Like