Why isn't the ellipse displaying?

Title is pretty self-explanatory, i need help to see what’s wrong with my code. Any help is appreciated, thanks!

class Ellipse {
  int x;
  int y;
  int w;
  int h;
  int c;
  Ellipse(int inputX, int inputY, int inputWidth, int inputHeight, color inputColor) {
    inputX = x;
    inputY = y;
    inputWidth = w;
    inputHeight = h;
    inputColor = c;
  }
  void displayEllipse() {
    fill(c);
    ellipse(x, y, w, h);
  }
}

void setup() {
  size(200, 200);
}

void draw() {
  Ellipse myEllipse = new Ellipse(100, 100, 5, 5, 0);
  myEllipse.displayEllipse();
}

Hi,

You inverted the variables in your constructor.
inputX = x; should be x = inputX;

Also, it is bad practice to rebuild your object in each draw loop if you are going to reuse it all the time. Instead, move Ellipse myEllipse = new Ellipse(100, 100, 5, 5, 0); in setup.

2 Likes