将变量应用于处理 3 的屏幕尺寸 [英] applying variable to screen size on processing 3

查看:54
本文介绍了将变量应用于处理 3 的屏幕尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码在处理 2 中工作正常,但在 size() 函数中使用处理 3 中的变量不起作用,我将如何在处理 3 中实现 displaywdith-100

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

推荐答案

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

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() 已添加,使 size(displayWidth, displayHeight) 过时.因此,规则已从不鼓励变为不允许.

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

然而,他们还添加了一个新函数 settings(),它允许使用带有 size() 的变量:

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

请参阅此处:

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

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.

这篇关于将变量应用于处理 3 的屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆