在处理 3 时将变量应用于屏幕尺寸

msa*_*a12 4 java processing

该代码在处理 2 中工作正常,但在 size() 函数中使用处理 3 中的变量不起作用,我将如何在处理 3 中实现 displaywdith-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
Run Code Online (Sandbox Code Playgroud)

Max*_*mer 5

使用size()变量总是不鼓励的,但它是允许的,因为这size(displayWidth, displayHeight)是创建全屏草图的唯一方法。

在处理中fullScreen()添加了 3,使其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
Run Code Online (Sandbox Code Playgroud)

这里

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