Problem to make two Bezier curves evolve independently of each other

Hello,
I would like to evolve two Bezier curves independently.
I would like both to have a rotation in the center of the screen.
However, the second has a completely different behavior.
What is the coding so that two figures evolve distinctly.
Thanks in advance

float rx =0, rx2 =0;
float ry = 0, ry2 = 0;
float rz = 0, rz2 = 0;

void setup() {
fullScreen(P3D);
stroke(255);
noFill();
}

void draw() {
background(0);
B1();
B2();

}

void B1()
{
translate(width/2, height/2);
rotateX(rx);
rotateY(ry);
rotateZ(rz);
rx = rx+0.005;
ry = ry+0.015;
rz = rz+0.025;
for (int i = 0; i < 200; i += 20) {
bezier(1-(i/2.0), 40+i, -100, 410, 20, 100, 440, 300, 5, 240-(i/16.0), 300+(i/8.0), -50);
}
}

void B2()
{
translate(width/2, height/2);
rotateX(rx2);
rotateY(ry2);
rotateZ(rz2);
rx2 = rx2+0.0005;
ry2 = ry+20.0015;
rz2 = rz2+0.00025;
for (int i2 = 0; i2 < 200; i2 += 20) {
bezier(1-(i2/2.0), 40+i2, -100, 410, 20, 100, 440, 300, 5, 240-(i2/16.0), 300+(i2/8.0), -50);
}
}

1 Like

The solution is to use the push and pop methods to isolate transformations. Note I have added these to the methods B1 and B2

float rx =0, rx2 =0;
float ry = 0, ry2 = 0;
float rz = 0, rz2 = 0;

void setup() {
  fullScreen(P3D);
  stroke(255);
  noFill();
}

void draw() {
  background(0);
  B1();
  B2();
}

void B1() {
  push();
  translate(width/2, height/2);
  rotateX(rx);
  rotateY(ry);
  rotateZ(rz);
  rx = rx+0.005;
  ry = ry+0.015;
  rz = rz+0.025;
  for (int i = 0; i < 200; i += 20) {
    bezier(1-(i/2.0), 40+i, -100, 410, 20, 100, 440, 300, 5, 240-(i/16.0), 300+(i/8.0), -50);
  }
  pop();
}

void B2() {
  push();
  translate(width/2, height/2);
  rotateX(rx2);
  rotateY(ry2);
  rotateZ(rz2);
  rx2 = rx2+0.0005;
  ry2 = ry+20.0015;
  rz2 = rz2+0.00025;
  for (int i2 = 0; i2 < 200; i2 += 20) {
    bezier(1-(i2/2.0), 40+i2, -100, 410, 20, 100, 440, 300, 5, 240-(i2/16.0), 300+(i2/8.0), -50);
  }
  pop();
}
3 Likes

Sorry for being late in responding, this is the right solution.
It’s recorded
Thanks Quark