3
$\begingroup$

I´m new to the Processing language. Trying to do my first sketch I´m having trouble with the dimension of the display window width and height because even though I´ve tried putting a variety of values in the size() function, the size of the window doesn´t change at any time, it always has the same size (100px x 100px). The function fullScreen() has the same results. How could I resolve this problem?

It´s a simple visualization of a "star field". First block, class Star, simply create a star and fill it with a color. Second block is where I´m trying to adjust the size of the display window but it doesn´t work.

class Star {
  float x;
  float y;
  float z;

  Star(){
    // Places the star in random X and Y coordinates
    x = random(0, width);
    y = random(0, height);
  }

  /* Colors the star */
  void update(){
    fill(255);
    noStroke();
    ellipse(x, y, 8, 8);
  }

  void show(){}
  }

// Array that contains all the amount of stars created (100 in this case)
Star[] stars = new Star[100];

void Setup(){
  size(800, 800); // TROUBLE HERE. DOESN´T WORK
  for(int i = 0; i < stars.length; i++){
    stars[i] = new Star();
  }
}

void Draw(){
  background(0); // Colors the background
  for(int i = 0; i < stars.length; i++){
    stars[i].update();
    stars[i].show();
  }
}
$\endgroup$

1 Answer 1

1
$\begingroup$

The window is 100px, 100px because it is the default size and you are not changing it, as your size() is never being called because Setup() is not a predefined function. setup() is the function, lower case s not upper case S. Same with draw().

Below is the working code.

class Star {
  float x;
  float y;
  float z;

  Star(){
    // Places the star in random X and Y coordinates
    x = random(0, width);
    y = random(0, height);
  }

  /* Colors the star */
  void update(){
    fill(255);
    noStroke();
    ellipse(x, y, 8, 8);
  }

  void show(){}
  }

// Array that contains all the amount of stars created (100 in this case)
Star[] stars = new Star[100];

void setup(){
  size(800, 800); // TROUBLE HERE. DOESN´T WORK
  for(int i = 0; i < stars.length; i++){
    stars[i] = new Star();
  }
}

void draw(){
  background(0); // Colors the background
  for(int i = 0; i < stars.length; i++){
    stars[i].update();
    stars[i].show();
  }
}
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.