Good day dear. Wondered how to hold the color of the rgb format across the entire color chart? How to make a function to recalculate the number of each channel? I will give an example http://colorscheme.ru/ let's say we have an array of flowers

.st1{fill: rgb(223,34,89);} .st2{fill:rgb(238,82,148);} .st3{fill:rgb(178,52,91);} .st4{fill:rgb(204,49,113);} .st5{fill:rgb(237,62,116);} .st6{fill:rgb(173,48,94);} .st7{fill:rgb(209,67,119);} .st8{fill:rgb(153,27,65);} .st9{fill:rgb(213,39,88);} .st10{fill:rgb(172,29,69);} .st11{fill:rgb(204,55,102);} .st12{fill:rgb(136,24,64);} .st13{fill:rgb(207,62,115);} .st14{fill:rgb(192,36,87);} .st15{fill:rgb(150,47,90);} .st16{fill:rgb(178,54,98);} .st17{fill:rgb(150,42,76);} .st18{fill:rgb(178,48,101);} .st19{fill:rgb(157,29,80);} .st20{fill:rgb(183,55,101);} .st21{fill:rgb(186,36,92);} .st22{fill:rgb(247,87,145);} .st23{fill:rgb(200,35,90);} .st25{fill:rgb(242,144,187);} .st26{fill:rgb(219,62,120);} 

How to bypass all these colors in a circle diagram? What is addiction?

  • What do you mean by "hold color .. across the whole color chart"? What do you mean by "function to recalculate the number of the channel"? - Kromster
  • one
    the question is not correct .. there are many color models and color spaces, which determine the formulas and methods for obtaining colors. The circle you are talking about is one color space, and rgb is completely different, so you will not be able to build a circle from rgb. In order to understand what needs to be done, it is necessary first of all to ask the right thing, and for that to figure it out for yourself. - user220409
  • I will try to explain in the figure. ! askMy.png That's how I have an array of flowers that must simultaneously pass along the perimeter of a circle with a sprite - BlackStar1991

1 answer 1

If you mean the conversion of the visible spectrum (380nm-780nm) to rgb, then I know this implementation of the well-known formula on js:

 function nmToRGB(wavelength){ var Gamma = 0.80, IntensityMax = 255, factor, red, green, blue; if((wavelength >= 380) && (wavelength<440)){ red = -(wavelength - 440) / (440 - 380); green = 0.0; blue = 1.0; }else if((wavelength >= 440) && (wavelength<490)){ red = 0.0; green = (wavelength - 440) / (490 - 440); blue = 1.0; }else if((wavelength >= 490) && (wavelength<510)){ red = 0.0; green = 1.0; blue = -(wavelength - 510) / (510 - 490); }else if((wavelength >= 510) && (wavelength<580)){ red = (wavelength - 510) / (580 - 510); green = 1.0; blue = 0.0; }else if((wavelength >= 580) && (wavelength<645)){ red = 1.0; green = -(wavelength - 645) / (645 - 580); blue = 0.0; }else if((wavelength >= 645) && (wavelength<781)){ red = 1.0; green = 0.0; blue = 0.0; }else{ red = 0.0; green = 0.0; blue = 0.0; }; // Let the intensity fall off near the vision limits if((wavelength >= 380) && (wavelength<420)){ factor = 0.3 + 0.7*(wavelength - 380) / (420 - 380); }else if((wavelength >= 420) && (wavelength<701)){ factor = 1.0; }else if((wavelength >= 701) && (wavelength<781)){ factor = 0.3 + 0.7*(780 - wavelength) / (780 - 700); }else{ factor = 0.0; }; if (red !== 0){ red = Math.round(IntensityMax * Math.pow(red * factor, Gamma)); } if (green !== 0){ green = Math.round(IntensityMax * Math.pow(green * factor, Gamma)); } if (blue !== 0){ blue = Math.round(IntensityMax * Math.pow(blue * factor, Gamma)); } return [red,green,blue]; } 

With it, you can go through the whole spectrum by simply applying it to the specified interval.

If you just need to go around all the points inside rgb. You can do it in three for loops, for example:

 var r; var g; var b; var maxColor = 255; var color; for(r = 0; r <= maxColor; r++){ for(g = 0; g <= maxColor; g++){ for(b = 0; b <= maxColor; b++){ color = 'rgb(' + r + ',' + g + ',' + b + ')'; } } } 
  • I got a little enlightened that I started to dig in the wrong place on this topic. Actually, I'm interested in the visualization function of HSV ru.wikipedia.org/wiki/… - BlackStar1991