在Processing 3中如何将变量应用于屏幕尺寸

4

这段代码在Processing 2中无问题,但是在Processing 3中使用size()函数的变量不起作用,我该如何在Processing 3中实现displaywidth-100?

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个回答

5

使用变量调用size()一直是不鼓励的,但是因为size(displayWidth, displayHeight)是创建全屏画布的唯一方式,所以它是允许的。

在Processing 3中,添加了fullScreen()函数,使得size(displayWidth, displayHeight)过时了。因此,规则从“不鼓励”变成了“不允许”。

然而,他们也添加了一个新的函数settings(),可以使用变量来调用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

请参见此处

settings() 函数是 Processing 3.0 中的新函数。大多数草图都不需要它。只有在绝对必要时,使用变量定义 size() 的参数时才有用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接