处理:从数组中选择随机颜色

发布于 2025-02-06 07:25:51 字数 590 浏览 1 评论 0原文

我正在尝试从阵列列表中选择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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧城烟雨 2025-02-13 07:25:51

在0到8之间生成一个随机#,然后使用该索引:

stroke(colors[(int)random(8)]);

或动态使用长度或颜色(如果它更改):

stroke(colors[(int)random(colors.length)]);

Generate a random # between 0 and 8, then use that index:

stroke(colors[(int)random(8)]);

or dynamically using the length or colors (in case it changes):

stroke(colors[(int)random(colors.length)]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文