# Width and height return 0

**URL:** https://discourse.processing.org/t/width-and-height-return-0/3177
**Category:** Coding Questions
**Created:** [September 1, 2018, 7:39pm UTC](https://discourse.processing.org/t/width-and-height-return-0/3177 "2018-09-01T19:39:32Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![BodaciousBrian](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@BodaciousBrian](https://discourse.processing.org/u/BodaciousBrian)
#### Post date: [September 1, 2018, 7:39pm UTC](https://discourse.processing.org/t/width-and-height-return-0/3177/1 "2018-09-01T19:39:32Z")

</div>

The following code, will always return x and y as 0… if I change displayWidth to width, it still returns 0. I’m using the apde editor on an s8+. How can I find the center of the display?  
(The +50 is there so I can see it when it returns 0)

```auto
void setup() {
  fullScreen(P2D);
  background(0);
}

int x = displayWidth/2;
int y = displayHeight/2;

void draw() {
     fill(100);
     ellipse(x+50, y+50, 30, 30);
}

```

---

<div class="post-metadata">

### Author: ![EnhancedLoop7](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/enhancedloop7/32/1040_2.png) [@EnhancedLoop7](https://discourse.processing.org/u/EnhancedLoop7)
#### Post date: [September 1, 2018, 8:14pm UTC](https://discourse.processing.org/t/width-and-height-return-0/3177/2 "2018-09-01T20:14:33Z")

</div>

From what I know, `displayWidth` and `displayHeight` cannot be set to equal another variable. I’m sure someone else can give a better explanation as to WHY that is 😃 What you would have to do is:

Which is specifically for your fullScreen code:

`ellipse( displayWidth/2, displayHeight/2, 30, 30);`

Which would then would put your ellipse at the center.

Another way you could do it for ANY sized screen, full screen or not, is by simply doing:

`ellipse(width/2,height/2,30,30);`

Ellipses are drawn around the center as you know, but you did say why you had the +50.

I think that the reason why you can’t set other variables equal to your width and height variables have to do with the fact that they are system variables. 🤔

Anyways, I hope that helps you. By the way, please make sure that you format your code 😃 It makes it look much nicer, and also is easier for us to read it!

You do that by highlighting your code and clicking the “Format” button, or by just highlighting it and pressing Control+Shift+C, Like this:

`System.out.println("I am formatted code!");`

EnhancedLoop7

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [September 2, 2018, 12:35am UTC](https://discourse.processing.org/t/width-and-height-return-0/3177/3 "2018-09-02T00:35:47Z")

</div>

> [@BodaciousBrian](#):
>
> int x = displayWidth/2;  
> int y = displayHeight/2;

You are assigning this value in the global scope of your sketch. You should initialize the values of these variable in `setup()` as that is the main purpose of this function. If you assign these values in the global scope, it is not guaranteed that Processing has initialized displayWidth/displayHeight properly. Also, you should use width and height instead.

Kf

---

<div class="post-metadata">

### Author: ![BodaciousBrian](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@BodaciousBrian](https://discourse.processing.org/u/BodaciousBrian)
#### Post date: [September 2, 2018, 3:30am UTC](https://discourse.processing.org/t/width-and-height-return-0/3177/4 "2018-09-02T03:30:05Z")

</div>

That worked like a charm… and wow! I never would have guessed that. Thank you for the help.
