生成n色彩虹调色板 [英] Generate a n-color rainbow palette

查看:141
本文介绍了生成n色彩虹调色板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用(



是否有众所周知的产生鲜艳彩虹色调色板的算法?

解决方案

要了解发生了什么,请尝试创建一个程序来显示每个值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);
}

您会看到以下内容:





注意生动的黄色带比例如绿色或蓝色带窄得多。这就是为什么仅对每个X值进行采样不会产生黄色的原因。



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

 大小(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);
}



或者您可以提前想出所需的值并将它们放在数组中,而不是

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

大小(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);
}


I'm trying to generate a rainbow with 15 different colors with (runnable code here):

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);
}

but it doesn't produce a rich 15 rainbow-color palette, instead some colors are missing (vivid yellow for example).

Is there a well known algorithm to produce a vivid rainbow color palette?

解决方案

To understand what's going on, try creating a program that shows a line for each value 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);
}

You'll see this:

Notice that the "vivid yellow" band is much more narrow than, for example, the green or blue bands. That's why simply sampling every X values doesn't generate a yellow color.

The yellow color is around value 60, so you could modify your increment so it lands on 60. Drawing 12 rectangles with a width of 30 lets you land on the yellow:

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);
}

Or you could come up with the values you want ahead of time and put them in an array instead of using an even distribution:

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);
}

这篇关于生成n色彩虹调色板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆