setup()
例子:
int x = 0;
void setup() {
size(200, 200);
background(0);
noStroke();
fill(102);
}
void draw() {
rect(x, 10, 2, 80);
x = x + 1;
}
int x = 0;
void setup() {
fullScreen();
background(0);
noStroke();
fill(102);
}
void draw() {
rect(x, height*0.2, 1, height*0.6);
x = x + 2;
}
描述:程序启动时,setup()函数运行一次。 它用于定义初始环境属性(如屏幕尺寸),并加载程序启动时的图像和字体等介质。 每个程序只能有一个setup()函数,在初始执行后不应再次调用它。
如果草图与默认尺寸不同,则size()函数或fullScreen()函数必须是setup()中的第一行。
注意:在其他函数中不能访问setup()中声明的变量,包括draw()。
语法: setup()
返回 空
相关:
size()
loop()
noLoop()
draw()
- 本文固定链接: http://iprocessing.cn/2017/06/30/setup初始化/
- 转载请注明: 卡萨布兰卡 于 Processing编程艺术 发表