处理:从数组中选择随机颜色
我正在尝试从阵列列表中选择strokeline的随机颜色。从程序中,它表明Random()期望参数如Random(float)。但是我对如何纠正它有些困扰。以下是我的代码:
int n = 200;
drop[] d;
color[] colors = {
#013a63,
#01497c,
#014f86,
#2a6f97,
#2c7da0,
#468faf,
#61a5c2,
#89c2d9,
#a9d6e5,
};
void setup() {
size(1080, 720);
stroke(random(colors));
d = new drop[n];
for(int i = 0; i < d.length; i ++) {
d[i] = new drop(random(width), random(-10, 20), random(5));
}
}
void draw() {
background(1, 42, 74,10);
for(int i = 0; i < d.length; i ++) {
d[i].show();
d[i].update();
}
}
I'm trying to pick a random color for strokeline from an array list. From the program, it indicates that random() expect parameter like random(float). But I feel a bit stuck of how to correct it. Below is my code:
int n = 200;
drop[] d;
color[] colors = {
#013a63,
#01497c,
#014f86,
#2a6f97,
#2c7da0,
#468faf,
#61a5c2,
#89c2d9,
#a9d6e5,
};
void setup() {
size(1080, 720);
stroke(random(colors));
d = new drop[n];
for(int i = 0; i < d.length; i ++) {
d[i] = new drop(random(width), random(-10, 20), random(5));
}
}
void draw() {
background(1, 42, 74,10);
for(int i = 0; i < d.length; i ++) {
d[i].show();
d[i].update();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在0到8之间生成一个随机#,然后使用该索引:
或动态使用长度或
颜色
(如果它更改):Generate a random # between 0 and 8, then use that index:
or dynamically using the length or
colors
(in case it changes):