# How do I change mouseX, mouseY default origin positions

**URL:** <https://discourse.processing.org/t/how-do-i-change-mousex-mousey-default-origin-positions/39780>\
**Category:** Coding Questions\
**Created:** [November 18, 2022, 5:39pm UTC](https://discourse.processing.org/t/how-do-i-change-mousex-mousey-default-origin-positions/39780 "2022-11-18T17:39:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siyue](https://avatars.discourse-cdn.com/v4/letter/s/9de0a6/32.png) [@Siyue](https://discourse.processing.org/u/Siyue)\
**Post date:** [November 18, 2022, 5:39pm UTC](https://discourse.processing.org/t/how-do-i-change-mousex-mousey-default-origin-positions/39780/1 "2022-11-18T17:39:39Z")

</div>

hey guys, this is a very small question.  
and here is my code:  
void setup() {  
size(600, 800);  
background(20, 40, 80);  
}  
void draw() {  
stroke(30,200,100,40);  
line(mouseX,mouseY,300,30);  
}  
void mousePressed(){background (20,190,220);}  
//void keyPressed(){background(100,20,10);}

but everytime when I refresh the canvas it appears a line from the top left to where my mouse is. I met this situation when I try to draw the squares. I mean it must be a fundamental problem.  
see as my attached  
 ![Screen Shot 2022-11-19 at 1.35.56 AM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/5/9/5957cf43420ebbb426e8384bc881f69ea9218a7e.png)

---

<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:** [November 18, 2022, 7:32pm UTC](https://discourse.processing.org/t/how-do-i-change-mousex-mousey-default-origin-positions/39780/2 "2022-11-18T19:32:25Z")

</div>

it’s not that simple

initially mouseX,mouseY is 0,0, so the initial line appears.

you can use the if-command to avoid this initial line:

```auto
void setup() {
  size(600, 800);
  background(20, 40, 80);
}

void draw() {
  stroke(30, 200, 100, 40);
  if (mouseX>0 && mouseY>0) { // !!!!!!!!!!!!!!!!
    line(300, 30, mouseX, mouseY );
  }
}

void mousePressed() {
  if (mouseButton==RIGHT) {
    background (20, 190, 220);
  }
}

//void keyPressed(){background(100,20,10);}

```

* * *

====================================================================

OR

use if(mousePressed) instead, so you need to hold the mouse to draw.

- then you want to use the RIGHT mouse button to clear the screen (see function mousePressed()).

```auto
void setup() {
  size(600, 800);
  background(20, 40, 80);
}

void draw() {
  stroke(30, 200, 100, 40);
  if (mousePressed) { // !!!!!!!!!!!!!!!!!!!!!!!!!!!!
    line(300, 30, mouseX, mouseY );
  }
}

void mousePressed() {
  if (mouseButton==RIGHT) { // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    background (20, 190, 220);
  }
}

//void keyPressed(){background(100,20,10);}

```

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [November 18, 2022, 8:27pm UTC](https://discourse.processing.org/t/how-do-i-change-mousex-mousey-default-origin-positions/39780/3 "2022-11-18T20:27:02Z")

</div>

Hello @Siyue!  
This is a great question!! 🙂

And I hope you don’t mind, but I altered the title of your post to make it more searchable for others with the same question!  
If you feel the title does not reflect your question, please of course feel free to revise.  
However, please use descriptive keywords.  
🤓

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [November 19, 2022, 1:17am UTC](https://discourse.processing.org/t/how-do-i-change-mousex-mousey-default-origin-positions/39780/4 "2022-11-19T01:17:44Z")

</div>

> [@Siyue](#):
>
> I met this situation when I try to draw the squares.

Hi

You can just draw lines with your code  
Because

```auto
line(mouseX,mouseY,300,30);

```

 ![Screenshot_2022-11-19-03-57-29-306](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/d/b/db011981bb6694455e633314becdff43fd6e3f76.jpeg)

You can Use point ()

[https://funprogramming.org/20-The-smallest-drawing-program-ever.html](https://funprogramming.org/20-The-smallest-drawing-program-ever.html)

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [November 19, 2022, 1:58am UTC](https://discourse.processing.org/t/how-do-i-change-mousex-mousey-default-origin-positions/39780/5 "2022-11-19T01:58:49Z")

</div>

Hello @Siyue,

Take a look here:

> **[mouseButton / Reference](https://processing.org/reference/mouseButton.html)**
>
> When a mouse button is pressed, the value of the system variable mouseButton is set to either LEFT, RIGHT, or CENTER, depending on which button is pressed. (If no button is…

I used LEFT for drawing and RIGHT for clearing.

There is a tutorial on Interactivity here:  
[https://processing.org/tutorials](https://processing.org/tutorials)

`:)`

---

<div class="post-metadata">

**Author:** ![vkbr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/vkbr/32/16844_2.png) [@vkbr](https://discourse.processing.org/u/vkbr)\
**Post date:** [November 19, 2022, 3:01am UTC](https://discourse.processing.org/t/how-do-i-change-mousex-mousey-default-origin-positions/39780/6 "2022-11-19T03:01:29Z")

</div>

This does not solve the problem, but I think is usefull to note that one can set `mouseX` and `mouseY`:

```auto

void setup() {
  size(600, 800);
  background(20, 40, 80);
  mouseX = 100;
  mouseY = 100;
}
void draw() {
  stroke(30, 200, 100, 40);
  line(mouseX, mouseY, 300, 30);
}
void mousePressed() {
  background (20, 190, 220);
}
//void keyPressed(){background(100,20,10);}

```

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [November 22, 2022, 2:31am UTC](https://discourse.processing.org/t/how-do-i-change-mousex-mousey-default-origin-positions/39780/7 "2022-11-22T02:31:55Z")

</div>

Hi

```auto
void setup() {
 size(1000,800);
background (0,124,255);
}

void draw() {
  
  if (mousePressed) {
    strokeWeight(6); 
    stroke(204, 102, 0);
    line(pmouseX, pmouseY, mouseX, mouseY);
  }
}

```

 ![Screenshot_2022-11-22-05-28-58-293](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/1/5/15162cede2e5e41b84be7a583daadcba6ee240af.jpeg)

---

<div class="post-metadata">

**Author:** ![Siyue](https://avatars.discourse-cdn.com/v4/letter/s/9de0a6/32.png) [@Siyue](https://discourse.processing.org/u/Siyue)\
**Post date:** [November 22, 2022, 3:27pm UTC](https://discourse.processing.org/t/how-do-i-change-mousex-mousey-default-origin-positions/39780/8 "2022-11-22T15:27:07Z")

</div>

hey Chris  
both way works. thank you !
