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

**URL:** <https://discourse.processing.org/t/how-to-combine-mouse-history-code-and-mousexy-based-rotation-code/31910>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [August 25, 2021, 4:43am UTC](https://discourse.processing.org/t/how-to-combine-mouse-history-code-and-mousexy-based-rotation-code/31910 "2021-08-25T04:43:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wwoni](https://avatars.discourse-cdn.com/v4/letter/w/ea666f/32.png) [@wwoni](https://discourse.processing.org/u/wwoni)\
**Post date:** [August 25, 2021, 4:43am UTC](https://discourse.processing.org/t/how-to-combine-mouse-history-code-and-mousexy-based-rotation-code/31910/1 "2021-08-25T04:43:03Z")

</div>

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.

```auto
-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();
}
}

```

```auto
-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();
}

```

```auto
-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();
    
  }
}

```
