random 这个函数有个坑, 你可以直接定义
stroke(random(255)); 不会报错,但得出来的不是随机数 equal==》 stroke(255),是个灰色的颜色;stroke(random(255),random(255),random(255)); 对应 R,G,B,写完整不要偷懒
所以下面代码的 转 int 在processing 3 中也是可以省略的
void setup(){
frameRate(60);
size(528,414);
}
void draw(){
//background(255);
int r = int(random(255));
int g = int(random(255));
int b = int(random(255));
int a = int(random(255));
println(r,g,b);
stroke(r,g,b,a);
line(width/2,height/2,random(width),random(height));
}
效果图如下: