applying variable to screen size on processing 3

こ雲淡風輕ζ 提交于 2020-01-24 05:51:09

问题


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:


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.



来源:https://stackoverflow.com/questions/58479759/applying-variable-to-screen-size-on-processing-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!