How can I generate a list of random shades of a particular color? (e.g. random shade of orange)

Sinaesthetic

Has anyone come across a way to choose a random shade of a particular color? Sounds silly at first, but what I'm trying to do is come up with an automated way to generate chart series colors, and those colors need to be branded. So it seems reasonable that there is a way to maybe generate a range of color values for a particular color range; I've some examples on the web but not the logic.

So I'm looking for a way to say: generate a list of shades of Red, or Orange, or Green, etc. "Well, what constitutes a 'green' ?" Ok well maybe if I provide a hex value, the library/class could determine that it is a green and then generate a list of other greens, etc. So that way, before rendering the chart, I could say "This brand uses a color scheme that uses lots of blues, so randomly choose series colors that are types of blues." Does that make sense? This is in either C# or Javascript would be helpful.

I'd rather understand how to build one myself, but if any libraries already exist out there, it would be helpful.

Roko C. Buljan

jsBin demo

The simplest way I can think of:

use hsl (Hue, Saturation, Lightness) colors.
The range is expressed like:

hsl([0-360], [0-100]%, [0-100]%)
      HUE     SATUR.    LIGHT.

Think of Hue as a 360° wheel where 0 and 360 are Red, in between you have all the other ones:

enter image description here

Now you can retrieve from that wheel 12 basic colors moving by steps of 30° :

0%  : RED
30% : ORANGE
60% : YELLOW
90% : CHARTREUSE GREEN
120%: GREEN
150%: TURQUOISE
180%: CYAN
210%: AZURE
240%: BLUE
270%: VIOLET
300%: MAGENTA
330%: ROSE

You can than generate some steps of lightness and saturation at random or by (i.e.) 20% steps.

Saturation: Having lightness at 50% and setting Saturation at 0% you'll get the exact equivalent of Pure Gray (HEX: #808080 RGB: rgb(128,128,128) *Wiki: Middle Gray) so think of saturation as a gray-to-full-color unit.

Lightness, range from 0% being black to 100% as white - applied to a selected color.

(Logically from the above you can conclude that lightness affects Saturation also.)


Let's put the above together!

var numOfShades = 20; // Set here the Desired number of Shades
var colorSELECT = document.getElementById('color');
var colorsDIV = document.getElementById('shades');

function rand(min, max){
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

function createSPAN( hsl ){
  var span = document.createElement('span');
  span.style.backgroundColor = hsl;
  colorsDIV.appendChild(span);
}

function generateShades(){
  colorsDIV.innerHTML = ""; // Empty from old SPANS
  var hue = this.value;     // The Select Value: 0->360

  createSPAN("hsl("+hue+", 100%, 50%)"); // Create The selected color!

  for(var i=0; i<numOfShades; i++){      // Create shades!
    var hsl = "hsl("+hue+", "+ rand(10,90) +"%, "+rand(10, 90) +"%)";
    createSPAN( hsl );
  }
}

colorSELECT.onchange = generateShades;
#shades > span{
  display:inline-block;
  margin:10px;
  width:60px;
  height:60px;
  border-radius:5px;
}
<select id="color">
  <option value="0"> RED</option>
  <option value="30">ORANGE</option>
  <option value="60">YELLOW</option>
  <option value="90">CHARTREUSE GREEN</option>
  <option value="120">GREEN</option>
  <option value="150">TURQUOISE</option>
  <option value="180">CYAN</option>
  <option value="210">AZURE</option>
  <option value="240">BLUE</option>
  <option value="270">VIOLET</option>
  <option value="300">MAGENTA</option>
  <option value="330">ROSE</option>
</select>

<div id="shades"></div>


As a final thought, instead of having a <select> bropdown, you could instead use a colorWheel image (like the one I've provided above), track the click coordinates and usign some simple trigonometry retrieve the correspondent degree that you can than use as hsl color.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I generate a list of random shades of a particular color? (e.g. random shade of orange)

From Dev

Generate random shades of green

From Dev

Android - How can I generate a random color with limits?

From Java

How can I generate random alphanumeric strings?

From Dev

How to generate random color for JSCharts

From Dev

How to generate random bright color?

From Dev

How to generate random bright color?

From Dev

MATLAB: How do I shade plot area with increasing and decreasing shades of a color

From Dev

How do I generate a random list in Python with duplicates numbers

From Dev

How to exclude all shades of gray while generating random hex color code?

From Dev

Generate a Random Color Java

From Dev

Generate random color

From Dev

Generate random color on hover

From Java

How can I generate three random integers that satisfy some condition?

From Dev

How can I generate a random number within a range in Rust?

From Dev

How can I generate a "random constant colour" for a given string?

From Dev

How can I generate a random int using the "crypto/rand" package?

From Dev

How can I generate two random numbers(not repeated)?

From Dev

How can I generate random dates within a range?

From Dev

How can I generate a random number in a certain range?

From Dev

How can I generate a random number from a group of numbers (not a range)

From Dev

How can I generate a random timestamp appended to getdate() in SQL Server?

From Dev

How can I generate a random number every 24 hours in JavaScript?

From Dev

How can I generate a random number in a certain range?

From Dev

How can I generate a random angle in radians in this range?

From Dev

How can I generate a random number each time a variable is called?

From Dev

How can I generate a random unicode character in Swift?

From Dev

How can I generate a random number every x amount of months?

From Dev

How can I generate a random sequence of numbers in JavaScript with conditions?

Related Related

  1. 1

    How can I generate a list of random shades of a particular color? (e.g. random shade of orange)

  2. 2

    Generate random shades of green

  3. 3

    Android - How can I generate a random color with limits?

  4. 4

    How can I generate random alphanumeric strings?

  5. 5

    How to generate random color for JSCharts

  6. 6

    How to generate random bright color?

  7. 7

    How to generate random bright color?

  8. 8

    MATLAB: How do I shade plot area with increasing and decreasing shades of a color

  9. 9

    How do I generate a random list in Python with duplicates numbers

  10. 10

    How to exclude all shades of gray while generating random hex color code?

  11. 11

    Generate a Random Color Java

  12. 12

    Generate random color

  13. 13

    Generate random color on hover

  14. 14

    How can I generate three random integers that satisfy some condition?

  15. 15

    How can I generate a random number within a range in Rust?

  16. 16

    How can I generate a "random constant colour" for a given string?

  17. 17

    How can I generate a random int using the "crypto/rand" package?

  18. 18

    How can I generate two random numbers(not repeated)?

  19. 19

    How can I generate random dates within a range?

  20. 20

    How can I generate a random number in a certain range?

  21. 21

    How can I generate a random number from a group of numbers (not a range)

  22. 22

    How can I generate a random timestamp appended to getdate() in SQL Server?

  23. 23

    How can I generate a random number every 24 hours in JavaScript?

  24. 24

    How can I generate a random number in a certain range?

  25. 25

    How can I generate a random angle in radians in this range?

  26. 26

    How can I generate a random number each time a variable is called?

  27. 27

    How can I generate a random unicode character in Swift?

  28. 28

    How can I generate a random number every x amount of months?

  29. 29

    How can I generate a random sequence of numbers in JavaScript with conditions?

HotTag

Archive