# X =width/2 not plotting to the middle of the sketch window

**URL:** <https://discourse.processing.org/t/x-width-2-not-plotting-to-the-middle-of-the-sketch-window/21585>\
**Category:** Beginners\
**Created:** [June 5, 2020, 10:16am UTC](https://discourse.processing.org/t/x-width-2-not-plotting-to-the-middle-of-the-sketch-window/21585 "2020-06-05T10:16:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BackTo](https://avatars.discourse-cdn.com/v4/letter/b/34f0e0/32.png) [@BackTo](https://discourse.processing.org/u/BackTo)\
**Post date:** [June 5, 2020, 10:16am UTC](https://discourse.processing.org/t/x-width-2-not-plotting-to-the-middle-of-the-sketch-window/21585/1 "2020-06-05T10:16:52Z")

</div>

Hello,

I have a very basic question. When I set the X coordinate to width/2 and the Y coordinate to height/2, the coordinate, plotted never ends up in the middle of the screen.

Is there some coding syntax I’m missing?

I have tried setting the width and height as floats globally and this solves the problem, but I thought that the ‘width’ and ‘height’ variables were set to the ‘size’ variables of the sketch by default. Is there something I’m missing.

```auto
float X= width/2;
float Y= height/2;

void setup(){
 size(200,200);
    background(255);
}
void draw(){
  strokeWeight(12);
  rect(X,Y,10,10);
 }

```

In the above example I’ve used a rect but it happens for all my features( line, ellipse and so on).

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [June 5, 2020, 10:46am UTC](https://discourse.processing.org/t/x-width-2-not-plotting-to-the-middle-of-the-sketch-window/21585/2 "2020-06-05T10:46:28Z")

</div>

`width` has a value of 0 until after `size()` is called.

You should set the values of `X` and `Y` inside `setup()` instead, after `size()` is called.

---

<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 5, 2020, 10:52am UTC](https://discourse.processing.org/t/x-width-2-not-plotting-to-the-middle-of-the-sketch-window/21585/3 "2020-06-05T10:52:51Z")

</div>

Yeah, well spotted

but you still have declare X and Y before setup()  
so they are known in all functions.

```auto
float X;
float Y;

```

---

<div class="post-metadata">

**Author:** ![BackTo](https://avatars.discourse-cdn.com/v4/letter/b/34f0e0/32.png) [@BackTo](https://discourse.processing.org/u/BackTo)\
**Post date:** [June 5, 2020, 11:05am UTC](https://discourse.processing.org/t/x-width-2-not-plotting-to-the-middle-of-the-sketch-window/21585/4 "2020-06-05T11:05:06Z")

</div>

Thanks, I didn’t know that about ‘size’. It explains a lot about other issues I have been experiencing. Thanks again.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 5, 2020, 6:16pm UTC](https://discourse.processing.org/t/x-width-2-not-plotting-to-the-middle-of-the-sketch-window/21585/5 "2020-06-05T18:16:58Z")

</div>

Hello,

Using println() wisely can be a great tool for understanding your code:  
[https://processing.org/reference/println\_.html](https://processing.org/reference/println_.html)

`:)`
