# Set size() from calculations within the sketch

**URL:** <https://discourse.processing.org/t/set-size-from-calculations-within-the-sketch/31594>\
**Category:** Processing.py\
**Created:** [August 6, 2021, 10:46am UTC](https://discourse.processing.org/t/set-size-from-calculations-within-the-sketch/31594 "2021-08-06T10:46:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LindowMan](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lindowman/32/14031_2.png) [@LindowMan](https://discourse.processing.org/u/LindowMan)\
**Post date:** [August 6, 2021, 10:46am UTC](https://discourse.processing.org/t/set-size-from-calculations-within-the-sketch/31594/1 "2021-08-06T10:46:28Z")

</div>

Hi!  
I searched the forum but didn’t really find an answer…

 ![Screenshot (644)](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/3da0a449078b6c7f3a82c23e2556b2d1f7bbc1c7.png)

I have a sketch that generates a list of lists of integers(it’s what the apply\_rule function in the screenshot does). Some calculations are performed and I want to set the size of the sketch window to the values derived from the output of the function.  
Now I might be mistaken but it seems that size() has to be the first thing set in a sketch even for sketches that don’t use setup() (which I don’t here). My problem is that I have to run the calculations before I can tell the sketch what size I want for the sketch. But of course, running the sketch pops up a window right away, at the default size of 100,100, before the calculations are finished(it’s potentially a lot of values and the calculation for a factor of 1000 takes about a minute for example). Is there any way or workaround for this?  
Note: In this case my output is deterministic so I actually could calculate them externally and then just use the values but I would also be interested in seeing how this can be done for future projects that involve non-deterministic values. Hope this makes sense, thanks a lot!

---

<div class="post-metadata">

**Author:** ![StainlessHolz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stainlessholz/32/13542_2.png) [@StainlessHolz](https://discourse.processing.org/u/StainlessHolz)\
**Post date:** [August 6, 2021, 10:53am UTC](https://discourse.processing.org/t/set-size-from-calculations-within-the-sketch/31594/2 "2021-08-06T10:53:53Z")

</div>

Have a look at these surface options:  
[https://processing.org/reference/setResizable\_.html](https://processing.org/reference/setResizable_.html)  
Also with `surface.setSize();` you can change it afterwards.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 6, 2021, 11:57am UTC](https://discourse.processing.org/t/set-size-from-calculations-within-the-sketch/31594/3 "2021-08-06T11:57:47Z")

</div>

> [@LindowMan](#):
>
> … but it seems that **size()** has to be the first thing set in a sketch…

You can call **size()** anywhere within callback **settings()**: 💡

> **[settings() / Reference](https://processing.org/reference/settings_.html)**
>
> The settings() function is new with Processing 3.0. It's not needed in most sketches. It's only useful when it's absolutely necessary to define the parameters to size() with a variable. …

Here’s a link for an example on how to it on Processing’s Python Mode: 🐍

> [@Use a list to updatePixels()](https://discourse.processing.org/t/use-a-list-to-updatepixels/16268/10):
>
> filter() already got the GRAY type: [Py.Processing.org/reference/filter.html](http://Py.Processing.org/reference/filter.html) It converts all colors to 1 of the 256 grey tones. You state you require 6 shades instead. So we just need to use POSTERIZE after GRAY in order to get the desired effect: """ Gray Posterized PImage (v1.0.1) GoToLoop (2019-Dec-09) https://Discourse.Processing.org/t/use-a-list-to-updatepixels/16268/10 """ def hex6Digits(v): return str(hex(v, 6)) def mapToHex(container): return tuple(map(hex6Digits, container)) FIL…

---

<div class="post-metadata">

**Author:** ![LindowMan](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lindowman/32/14031_2.png) [@LindowMan](https://discourse.processing.org/u/LindowMan)\
**Post date:** [August 6, 2021, 12:33pm UTC](https://discourse.processing.org/t/set-size-from-calculations-within-the-sketch/31594/4 "2021-08-06T12:33:21Z")

</div>

thanks a lot that did it for me! Wasn’t aware of settings()…

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 6, 2021, 12:39pm UTC](https://discourse.processing.org/t/set-size-from-calculations-within-the-sketch/31594/5 "2021-08-06T12:39:09Z")

</div>

Indeed some Processing functions, even important 1s, aren’t listed in Python Mode’s reference: 😑  
[Py.Processing.org/reference/](http://Py.Processing.org/reference/)
