Error: error on "int"

Error: error on "int"

我是 Processing 的新手,我需要创建一种随机颜色,但 returns 出错了。

int R = (int)(Math.random()*255);
int G = (int)(Math.random()*255);
int B = (int)(Math.random()*255);
color randomColor = new color(R,G,B);

"int" 上此 returns 错误的最后一行 我是不是最后一行没写好?

其他答案没有意识到 color 是 Processing 中的一种类型。

您的问题是您正在尝试使用不存在的 new color() 构造函数。只需使用 color() 函数,如下所示:

color randomColor = color(R,G,B);

可以在 the reference 中找到更多信息。

另请注意,Processing 有自己的 random() 函数,您应该使用它而不是直接调用 Math.random() 自己。

编辑:原来其他人对此感到困惑,here是关于实现更好的错误消息的讨论。