# Assign a variable from draw function to setup function

**URL:** <https://discourse.processing.org/t/assign-a-variable-from-draw-function-to-setup-function/11022>\
**Category:** Coding Questions\
**Created:** [May 8, 2019, 6:02am UTC](https://discourse.processing.org/t/assign-a-variable-from-draw-function-to-setup-function/11022 "2019-05-08T06:02:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![l3ehfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/l3ehfar/32/4074_2.png) [@l3ehfar](https://discourse.processing.org/u/l3ehfar)\
**Post date:** [May 8, 2019, 6:02am UTC](https://discourse.processing.org/t/assign-a-variable-from-draw-function-to-setup-function/11022/1 "2019-05-08T06:02:40Z")

</div>

I just wanted to assign mouseX value to one of my parameters value in setup function. how should I assign something that needs to run continuously in setup function?

```auto
morphDo(){
    for (let a = startA; a < 360; a += spacing) {
      if (a % 30 == 0) {
        radius = map(mouseX, 0, width, 89, 110);
      } else {
        radius = 100;
      }
  }
}

```

```auto
function setup() {
  morph = new Morph();
  morph.morphDo();
}

```

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

---

<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:** [May 8, 2019, 7:54am UTC](https://discourse.processing.org/t/assign-a-variable-from-draw-function-to-setup-function/11022/2 "2019-05-08T07:54:43Z")

</div>

the setup can not read the mouse  
and if you would have something running forever in setup, the draw would never start.

when the setup is finished the draw starts to run ( 60 times per second default )  
and can read between its runs mouse and keyboard.

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [May 8, 2019, 8:53am UTC](https://discourse.processing.org/t/assign-a-variable-from-draw-function-to-setup-function/11022/3 "2019-05-08T08:53:04Z")

</div>

can you not just put your code in one of the many mouse functions already included in processing or simply create a function, which is called in draw?

Otherwise I would assume you can simply assign your variable globally outside of setup and call it within setup after. ie

float x = mouseX;

function setup(){  
var a = x + somecode…;

}
