How to draw a rectangle at the center of the screen using fullScreen() function?

edited January 2017 in Questions about Code

I have no idea why variables x and y gives me value 50.

// GLOBAL VARIABLES
float x = width / 2;
float y = height / 2;

float rectWidth = 50;
float rectHeight = 75;


void setup(){
  fullScreen();

  println(width + " WIDTH");
  println(height + " HEIGHT");
  println(x + " X");
  println(y + " Y");
}

void draw(){
  background(0);
  fill(255);
  rect(x, y, rectWidth, rectHeight);
}

In console I get this:

1366 WIDTH
768 HEIGHT
50.0 X
50.0 Y
Tagged:

Answers

  • Width and height do NOT work before size or fullScreen

    you need to split the lines up and call them in setup after size / fullscreen

  • I need to initialize x and y variables in setup() function :((

    Thank you as always Chrisir ;)

Sign In or Register to comment.