Skip to content
Daniel Schauer edited this page Jun 13, 2017 · 6 revisions

randPrttyClrs is a JavaScript library that generates random, pretty colors

Limits the random colors in both their saturation and luminance values to avoid overly bright, or overly dull/gray colors

Color picker showing aproximate constraints on saturation and luminance, plus picker control explanations

Basic usage

<script type="text/javascript" src="../rpc.js"></script>
<script type="text/javascript">
 $(document).ready(function(){
  $("DIV").each(function(){
    var cPair = rpc.getRandomPrettyColorPair("HSL");
    $(this).css({"background-color":cPair[1],"color":cPair[0]});
  });
 });
</script>

Use Cases

  1. Generate a pair of colors, one darker and one lighter, for the same hue

    This code will generate a pair of CSS HSL color values for a random hue. The first color element in the returned array is for the darker shade, and the second element is for the lighter shade.

    var cPair = rpc.getRandomPrettyColorPair("HSL");
    $("DIV").each(function(){
      $(this).css({"background-color":cPair[0],"color":cPair[1]});
    });
Clone this wiki locally