将 3 个类型的数字分配给 Processing 中的变量
Assign 3 typed numbers to a variable in Processing
我正在 Processign 中制作一个绘画程序,并希望允许用户键入 3 个数字来更改 int r;。
我想知道我是否可以做一些事情来获取三个类型的数字并将它们分配给像 int r 这样的单个变量。比如输入2、5、5,存储为int r =255;
你可以使用数组。
数组是一个包含多个值的变量。
int[] r = {1, 2, 3};
int x = r[0];
Here 是处理数组引用。
您可以创建自己的 class。
更好的是,您可以创建一个 class 来跟踪您的 3 个值:
class MyNumbers{
int r;
int g;
int b;
public MyNumbers(int r, int g, int b){
this.r = r;
this.g = g;
this.b = b;
}
}
然后您只需创建一个 class 的实例并传入您的值:
MyNumbers rgb = new MyNumbers(1, 2, 3);
int r = rgb.r;
Here 是处理 class 参考。
您可以使用 color
类型。
如果您只想存储 rgb 值,请考虑在处理中使用现有的 color
类型:
color c = color(1, 2, 3);
int r = red(c);
Here为处理颜色参考。
我正在 Processign 中制作一个绘画程序,并希望允许用户键入 3 个数字来更改 int r;。 我想知道我是否可以做一些事情来获取三个类型的数字并将它们分配给像 int r 这样的单个变量。比如输入2、5、5,存储为int r =255;
你可以使用数组。
数组是一个包含多个值的变量。
int[] r = {1, 2, 3};
int x = r[0];
Here 是处理数组引用。
您可以创建自己的 class。
更好的是,您可以创建一个 class 来跟踪您的 3 个值:
class MyNumbers{
int r;
int g;
int b;
public MyNumbers(int r, int g, int b){
this.r = r;
this.g = g;
this.b = b;
}
}
然后您只需创建一个 class 的实例并传入您的值:
MyNumbers rgb = new MyNumbers(1, 2, 3);
int r = rgb.r;
Here 是处理 class 参考。
您可以使用 color
类型。
如果您只想存储 rgb 值,请考虑在处理中使用现有的 color
类型:
color c = color(1, 2, 3);
int r = red(c);
Here为处理颜色参考。