# Dynamic Text size (responsive)

**URL:** <https://discourse.processing.org/t/dynamic-text-size-responsive/31491>\
**Category:** Coding Questions\
**Created:** [July 30, 2021, 8:35am UTC](https://discourse.processing.org/t/dynamic-text-size-responsive/31491 "2021-07-30T08:35:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Quorum](https://avatars.discourse-cdn.com/v4/letter/q/ad7895/32.png) [@Quorum](https://discourse.processing.org/u/Quorum)\
**Post date:** [July 30, 2021, 8:35am UTC](https://discourse.processing.org/t/dynamic-text-size-responsive/31491/1 "2021-07-30T08:35:47Z")

</div>

Hello, everyone,  
I would like the text to change size according to the choice of window size. But my code doesn’t work. Can you explain me why please?

```auto
let titleSize = floor(createNumberDict(12, setLayout[layoutMode][0]));

```

where setLayout is an array containing the different sizes and layoutMode is a variable I set manually to change the window size.

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [July 30, 2021, 1:00pm UTC](https://discourse.processing.org/t/dynamic-text-size-responsive/31491/2 "2021-07-30T13:00:24Z")

</div>

I don’t fully understand how your code works (since you didn’t post the whole version) but in general, you could change it with the help of `width & height` variables. The simplest example would be:

```auto
textSize(width*0.1); //the larger the width, the larget the text
//but this doesn't take into accound height!

```

Or you could do something like this (if you have window size options available to user)

```auto
if(width<100) textSize(5);
else if(width<200) textSize(10);
else if(width<300) textSize(15);
//and continue like this.

```

The 3rd option is to have everything automated. You let the user choose one of `n` presets:

```auto
if(sizePreset==0) textSize(15);
if(sizePreset==1) textSize(20);
if(sizePreset==2) textSize(50);
if(sizePreset==3) textSize(7);

```

Or you can automate this by using

```auto
textSize(textSizeArray[sizePreset]);
//or using a function to get/calculate it 
//(more flexible and no crashing 
//since you can set default value even if preset is out of range)
textSize(getTextSize(sizePreset));

```

---

<div class="post-metadata">

**Author:** ![Quorum](https://avatars.discourse-cdn.com/v4/letter/q/ad7895/32.png) [@Quorum](https://discourse.processing.org/u/Quorum)\
**Post date:** [September 1, 2021, 6:02am UTC](https://discourse.processing.org/t/dynamic-text-size-responsive/31491/3 "2021-09-01T06:02:18Z")

</div>

Thank you very much 😃 I’m a novice and I din’t noticed it.  
Your solution solved my problem 😃
