Skip to content

Instantly share code, notes, and snippets.

@chak10
Last active December 9, 2023 06:04
Show Gist options
  • Save chak10/dc24c61c9bf2f651cb6d290eeef864c1 to your computer and use it in GitHub Desktop.
Save chak10/dc24c61c9bf2f651cb6d290eeef864c1 to your computer and use it in GitHub Desktop.

Revisions

  1. chak10 revised this gist Jun 4, 2017. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion randomDarkColor.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,6 @@ function randDarkColor() {
    if (hex.length < 6) {
    hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
    }
    lum = lum || 0;
    var rgb = "#",
    c, i;
    for (i = 0; i < 3; i++) {
  2. chak10 created this gist Jun 4, 2017.
    16 changes: 16 additions & 0 deletions randomDarkColor.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    function randDarkColor() {
    var lum = -0.25;
    var hex = String('#' + Math.random().toString(16).slice(2, 8).toUpperCase()).replace(/[^0-9a-f]/gi, '');
    if (hex.length < 6) {
    hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
    }
    lum = lum || 0;
    var rgb = "#",
    c, i;
    for (i = 0; i < 3; i++) {
    c = parseInt(hex.substr(i * 2, 2), 16);
    c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
    rgb += ("00" + c).substr(c.length);
    }
    return rgb;
    }