applying variable to screen size on processing 3

Viewed 866

This code works fine in processing 2 but using variables in processing 3 in the size() function does not work, how would i go about implementing displaywdith-100 in processing 3

int val, screen_increment, old_x=0, old_y=0;     
String inString;  
int lf = 10;      
void setup() 
{

  size(displayWidth-100, 600);//  The screen height is set to be 600, which matches the scaled data,
  String portName = Serial.list()[0];
  println(Serial.list());

  myPort = new Serial(this, portName, 115200);
  myPort.bufferUntil(lf);
  background(0);
}//setup
1 Answers

Using size() with variables was always discouraged, however it was allowed because size(displayWidth, displayHeight) was the only way of creating a fullscreen sketch.

In Processing 3 fullScreen() was added, making size(displayWidth, displayHeight) obsolete. Thus the rules have changed from discouraged to not allowed.

However, they also added a new function settings(), which allows using variables with size():

void settings() {
    size(displayWidth-100, 600);
}

void setup() 
{
    String portName = Serial.list()[0];
    println(Serial.list());

    myPort = new Serial(this, portName, 115200);
    myPort.bufferUntil(lf);
    background(0);
}//setup

See here:

The settings() function is new with Processing 3.0. It's not needed in most sketches. It's only useful when it's absolutely necessary to define the parameters to size() with a variable.

Related