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



这段代码在处理 2 时工作正常,但在 size(( 函数的处理 3 中使用变量不起作用,我将如何在处理 100 中实现 displaywdith-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

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

在处理 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(( 函数是处理 3.0 中的新功能。在大多数草图中都不需要它。仅当绝对有必要使用变量定义 size(( 的参数时,它才有用。

最新更新