gpt4 book ai didi

colors - 生成 n 色彩虹调色板

转载 作者:行者123 更新时间:2023-12-02 09:01:03 26 4
gpt4 key购买 nike

我正在尝试使用 ( runnable code here ) 生成具有 15 种不同颜色的彩虹:

size(360,100);
colorMode(HSB, 360, 100, 100); // Hue in degrees in [0, 360],
// saturation/brightness in [0, 100]
// like in Photoshop
noStroke();

for (int i = 0; i < 15; i++)
{
fill(i*24, 100, 100); // 24*15 = 360
rect(i*24, 0, 25, 100);
}

但它不会产生丰富的 15 种彩虹调色板,而是缺少一些颜色(例如鲜艳的黄色)。

enter image description here

是否有一种众所周知的算法可以产生生动的彩虹调色板?

最佳答案

要了解发生了什么,请尝试创建一个程序,为 0-360 之间的每个值显示一行:

size(360,100);
colorMode(HSB, 360, 100, 100);
noStroke();
for (int i = 0; i < 360; i++)
{
fill(i, 100, 100);
rect(i, 0, 1, 100);
}

你会看到这个:

color gradient

请注意,“鲜艳的黄色”波段比绿色或蓝色波段窄得多。这就是为什么简单地对每个 X 值进行采样不会生成黄色。

黄色的颜色值约为 60,因此您可以修改增量,使其落在 60 上。绘制 12 个宽度为 30 的矩形可让您落在黄色上:

size(360,100);
colorMode(HSB, 360, 100, 100);
noStroke();
for (int i = 0; i < 360; i++)
{
fill(i*30, 100, 100);
rect(i*30, 0, 30, 100);
}

color gradient with yellow

或者您可以提前想出所需的值并将它们放入数组中,而不是使用均匀分布:

int[] hueValues = {0, 15, 30, 60, 90, 120, 150, 180, 210, 225, 240, 270, 300, 330, 360};

size(360,100);
colorMode(HSB, 360, 100, 100);
noStroke();
for (int index = 0; index < hueValues.length; index++)
{
float rectWidth = width/hueValues.length;
fill(hueValues[index], 100, 100);
rect(index*rectWidth, 0, rectWidth, height);
}

array color gradient

关于colors - 生成 n 色彩虹调色板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47858866/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com