# Is there a way stop the function "windowResized" to rerun the "draw"?

**URL:** https://discourse.processing.org/t/is-there-a-way-stop-the-function-windowresized-to-rerun-the-draw/32995
**Category:** Beginners
**Created:** [October 22, 2021, 2:30am UTC](https://discourse.processing.org/t/is-there-a-way-stop-the-function-windowresized-to-rerun-the-draw/32995 "2021-10-22T02:30:38Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![animanoir](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@animanoir](https://discourse.processing.org/u/animanoir)
#### Post date: [October 22, 2021, 2:30am UTC](https://discourse.processing.org/t/is-there-a-way-stop-the-function-windowresized-to-rerun-the-draw/32995/1 "2021-10-22T02:30:39Z")

</div>

Each time the windows is resized, the responsive function works as intended, but redrawing the canvas so all the sketch and its variables are recalculated.

I simply want to position words in a random way through out the window.

```auto
console.log('experimentsTitles.js is loaded.')

let titlesArray = ['1', '2','3', '4']

function setup() {

  createCanvas(windowWidth, windowHeight);

}

function draw() {

  clear()

  for(let i = 0; i<= titlesArray.length - 1; i++){

    let titleA = createA('/', titlesArray[i], '_blank')

    titleA.style('font-size', '5rem')

    titleA.style('text-decoration', 'none')

    titleA.position(random(width), random(height))

  }

  noLoop()

}

function windowResized() {

  resizeCanvas(windowWidth, windowHeight)

}

```

---

<div class="post-metadata">

### Author: ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)
#### Post date: [October 22, 2021, 7:06am UTC](https://discourse.processing.org/t/is-there-a-way-stop-the-function-windowresized-to-rerun-the-draw/32995/2 "2021-10-22T07:06:27Z")

</div>

Hi! I see 2 problems here. One is that `createA` is not drawing on canvas but creates an HTML tag independent from the canvas. So, even if you `clear`, these tags remain and that’s why you see the characters multiplying.

The second issue is that `random` is always random 😅 I think the straightforward way is to store these random x,y in an array at `setup` - perhaps you want to generate random numbers between 0-1 and scale by `width` or `height`, because literally these values change after the window is resized. Another way, which is easier but less flexible is to use `randomSeed`. This function makes sure that every time `random` is called, it will return the same values in order. I provide you with the latter solution, but I highly suggest you to try the first solution 🙂

```javascript
console.log('experimentsTitles.js is loaded.')

let titlesArray = ['1', '2','3', '4']
let titleAs = [];

function setup() {

  createCanvas(windowWidth, windowHeight);

  randomSeed(7);
  for(let i = 0; i<= titlesArray.length - 1; i++){

    let titleA = createA('/', titlesArray[i], '_blank')

    titleA.style('font-size', '5rem')

    titleA.style('text-decoration', 'none')

    titleA.position(random() * width, random() * height)
    titleAs.push(titleA)
  }

}

function windowResized() {

  resizeCanvas(windowWidth, windowHeight)
  
  randomSeed(7);
  for(let i = 0; i<= titleAs.length - 1; i++){

    let titleA = titleAs[i];

    titleA.position(random() * width, random() * height)

  }

}

```

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

---

<div class="post-metadata">

### Author: ![animanoir](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@animanoir](https://discourse.processing.org/u/animanoir)
#### Post date: [October 22, 2021, 4:23pm UTC](https://discourse.processing.org/t/is-there-a-way-stop-the-function-windowresized-to-rerun-the-draw/32995/3 "2021-10-22T16:23:18Z")

</div>

Thank you very much! Learned a lot from this.
