# How to use this code with mousePressed?

**URL:** <https://discourse.processing.org/t/how-to-use-this-code-with-mousepressed/11925>\
**Category:** Beginners\
**Created:** [June 8, 2019, 3:37pm UTC](https://discourse.processing.org/t/how-to-use-this-code-with-mousepressed/11925 "2019-06-08T15:37:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joysaha573](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@joysaha573](https://discourse.processing.org/u/joysaha573)\
**Post date:** [June 8, 2019, 3:37pm UTC](https://discourse.processing.org/t/how-to-use-this-code-with-mousepressed/11925/1 "2019-06-08T15:37:25Z")

</div>

I want to appear this circile when mouse is pressed only. Please help with this

```auto
float angle = 0.00; 
float offset = 60 ; 
float scalar = 30; 
float speed = 0.05; 

void setup () {
  size (120, 120);  
  smooth () ;
}

void draw () {  
  float x = offset + cos (angle) * scalar ; 
  float y = offset + sin (angle) * scalar ; 
  ellipse ( x, y, 40, 40); 
  angle += speed;
}

```

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [June 8, 2019, 3:41pm UTC](https://discourse.processing.org/t/how-to-use-this-code-with-mousepressed/11925/2 "2019-06-08T15:41:24Z")

</div>

Hey There!

There is a void mousePressed method within processing !

[https://processing.org/reference/mousePressed\_.html](https://processing.org/reference/mousePressed_.html)

---

<div class="post-metadata">

**Author:** ![joysaha573](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@joysaha573](https://discourse.processing.org/u/joysaha573)\
**Post date:** [June 8, 2019, 4:12pm UTC](https://discourse.processing.org/t/how-to-use-this-code-with-mousepressed/11925/3 "2019-06-08T16:12:47Z")

</div>

I want to make it like when and where i click the mouse this will appear there only. I am unable to figure out. would u plz help me?

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [June 8, 2019, 4:32pm UTC](https://discourse.processing.org/t/how-to-use-this-code-with-mousepressed/11925/4 "2019-06-08T16:32:42Z")

</div>

Just put all that code into the mousePressed() method from draw()!

---

<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:** [June 8, 2019, 6:10pm UTC](https://discourse.processing.org/t/how-to-use-this-code-with-mousepressed/11925/5 "2019-06-08T18:10:21Z")

</div>

Yes.

Also look at mouseX and mouseY in the reference

[https://www.processing.org/reference/](https://www.processing.org/reference/)
