How to combine mouse history code and mouseXY-based rotation code

Hello, I am a self-taught student.
I’d like to combine the mouse history code and mouse rotation code below.
But when I put it together, the larger the x- and y-coordinates of the mousexy, the farther away the object is

This is the only place I can ask .
I don’t learn this at school and it’s an unfamiliar program in my country.

-mousehistory-

int[] xpos = new int[50]; 
int[] ypos = new int[50];



void setup() {
  size(2000,1000);


  for (int i = 0; i < xpos.length; i ++ ) {
    xpos[i] = 0; 
    ypos[i] = 0;
  }
}

void draw() {
  background(255);
   

 
  for (int i = 0; i < xpos.length-1; i ++ ) {
    xpos[i] = xpos[i+1];
    ypos[i] = ypos[i+1];
  }

  
  xpos[xpos.length-1] = mouseX; 
  ypos[ypos.length-1] = mouseY;


  for (int i = 0; i < ypos.length; i ++ ) {
    noStroke();
    fill(255-i*5);
    
  noStroke();
  beginShape();
  vertex(xpos[i]-100, ypos[i]+100);
  bezierVertex(xpos[i]-100, ypos[i]-40, xpos[i]+100, ypos[i]-40, xpos[i]+100, ypos[i]+100);
  bezierVertex(xpos[i]+100, ypos[i]-40, xpos[i]+300, ypos[i]-40, xpos[i]+300, ypos[i]+100);
  bezierVertex(xpos[i]+300, ypos[i]+200, xpos[i]+100, ypos[i]+300, xpos[i]+100, ypos[i]+400);
  bezierVertex(xpos[i]+100, ypos[i]+300, xpos[i]-100, ypos[i]+200, xpos[i]-100, ypos[i]+100);
  endShape();
}
}
-mouserotate-

void setup() {
  size(2000,1000);

}
float angle;
void draw() {
  background(255);
   
  if (mouseY != pmouseY && mouseX != pmouseX) {
    angle = atan2(mouseY-pmouseY, mouseX-pmouseX);
  }

    
  noStroke();
  translate(mouseX, mouseY);
  beginShape();
  fill(0);
  rotate(angle);
  beginShape();
  vertex(100, 200);
  vertex(-100, +100);
  bezierVertex(-100, -40, 100, -40, 100, 100);
  bezierVertex(+100, -40, 300, -40, 300, 100);
  bezierVertex(+300, +200, 100, 300, 100, 400);
  bezierVertex(+100, +300, -100, 200, -100, 100);
  endShape();

  endShape();
}
-myresult-
int[] xpos = new int[50]; 
int[] ypos = new int[50];



void setup() {
  size(2000,1000);


  for (int i = 0; i < xpos.length; i ++ ) {
    xpos[i] = 0; 
    ypos[i] = 0;
  }
}
float angle;
void draw() {
  background(255);
   
 if (mouseY != pmouseY && mouseX != pmouseX) {
    angle = atan2(mouseY-pmouseY, mouseX-pmouseX);
  }
 
  for (int i = 0; i < xpos.length-1; i ++ ) {
    xpos[i] = xpos[i+1];
    ypos[i] = ypos[i+1];
  }

  
  xpos[xpos.length-1] = mouseX; 
  ypos[ypos.length-1] = mouseY;


  for (int i = 0; i < ypos.length; i ++ ) {
    noStroke();
    fill(255-i*5);
  
  pushMatrix();  
 
  translate(mouseX, mouseY);
  rotate(angle);
//scale(0.6); *The smaller the size, the more visible the problem is.*  
  noStroke();
  beginShape();
  vertex(xpos[i]-100, ypos[i]+100);
  bezierVertex(xpos[i]-100, ypos[i]-40, xpos[i]+100, ypos[i]-40, xpos[i]+100, ypos[i]+100);
  bezierVertex(xpos[i]+100, ypos[i]-40, xpos[i]+300, ypos[i]-40, xpos[i]+300, ypos[i]+100);
  bezierVertex(xpos[i]+300, ypos[i]+200, xpos[i]+100, ypos[i]+300, xpos[i]+100, ypos[i]+400);
  bezierVertex(xpos[i]+100, ypos[i]+300, xpos[i]-100, ypos[i]+200, xpos[i]-100, ypos[i]+100);
  endShape();

  popMatrix();
    
  }
}