# Using the Mouse as a Drawing Tool

**URL:** https://discourse.processing.org/t/using-the-mouse-as-a-drawing-tool/13833
**Category:** Coding Questions
**Created:** [September 5, 2019, 8:52pm UTC](https://discourse.processing.org/t/using-the-mouse-as-a-drawing-tool/13833 "2019-09-05T20:52:33Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![van326](https://avatars.discourse-cdn.com/v4/letter/v/a6a055/32.png) [@van326](https://discourse.processing.org/u/van326)
#### Post date: [September 5, 2019, 8:52pm UTC](https://discourse.processing.org/t/using-the-mouse-as-a-drawing-tool/13833/1 "2019-09-05T20:52:33Z")

</div>

Hi! I am currently playing around with coding the ability to draw in p5.js, and so far it’s turning out okay, but I have a question about using the mouse as a brush. Ideally, I would like to have it where whenever the user clicks the mouse (mousePressed), the brush will stop making lines, and then continue making lines when it is pressed again. I currently also have it set to whenever the mouse is pressed, the background is cleared and recreated. When I tried typing in the code to have both the background reset and the brush stop/start, the brush stopped appearing.

Am I missing a step to add the ability to control when the brush is and isn’t being used, or am I ordering the information incorrectly? I have attached a link to my sketches; you can view the project that is named “Sketchy Sketch.” Thanks in advance!!

[https://editor.p5js.org/van326/sketches](https://editor.p5js.org/van326/sketches)

---

<div class="post-metadata">

### Author: ![colin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/colin/32/230_2.png) [@colin](https://discourse.processing.org/u/colin)
#### Post date: [September 5, 2019, 10:51pm UTC](https://discourse.processing.org/t/using-the-mouse-as-a-drawing-tool/13833/2 "2019-09-05T22:51:00Z")

</div>

Hi, @van326

By not displaying your background you managed to keep a track of the mouse of your user, but this trick wont be enough to go further.

There is plenty of way of doing a paint like sketch, I suggest you to use an array of vector.

Here is an example of how array works in p5  
[https://p5js.org/examples/arrays-array.html](https://p5js.org/examples/arrays-array.html)

And here is how to use vector  
[https://p5js.org/reference/#/p5/createVector](https://p5js.org/reference/#/p5/createVector)

Feel free to ask if you need help 🙂

Also, you can share each of your sketches separately in the p5 editor in the file tab -\> share

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [September 6, 2019, 2:34am UTC](https://discourse.processing.org/t/using-the-mouse-as-a-drawing-tool/13833/3 "2019-09-06T02:34:11Z")

</div>

BUT if you not want go from PAINT Mode to CONSTRUCT Mode  
here a small idea of a nice paint tool i made in JAVA Mode but just now translated for you ( using my )

> Mouse Wheel Plus Plus

> **[p5.js Web Editor](https://editor.p5js.org/kll/sketches/Vj-GWWxKV)**
>
> A web editor for p5.js, a JavaScript library with the goal of making coding accessible to artists, designers, educators, and beginners.

 ![p5jsMWPP_painter](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/9d702bb7ddf685225f54bbacf83f684bdb669783.png)

```auto
use mouse LEFT press for paint, RIGHT press for erase 
MousewheelPlusPlus: press
[r] red
[g] green
[b] blue
[w] brush size
and turn mousewheel 

```
