Is it possible to find darker/lighter shades from a hexadecimal?

Asked

Viewed 172 times

2

Given any color in the notation Hexadecimal, is it possible to find the same in lighter or darker tones? example...

    div {
      height: 50px;
      width: 150px;
      display: inline-block;
      text-align: center;
      line-height: 50px;
      margin-top:0px;
    }
    div:nth-child(1) {
      background: #5AAC56;
    }
    div:nth-child(2) {
      background: #338A2E;
    }
    div:nth-child(3) {
      background: #156711;
    }
    <div>Cor gerada</div>
    <div>Cor original</div>
    <div>Cor gerada</div>

  • 3

    It should be possible, this site does this https://highintegritydesign.com/tools/tinter-shader/

  • Opa vlw, I’ll take a look at the source code, if I get anything put here...

3 answers

2

There is a very simple way, but it does not offer much control.

To make it darker:

(corEmHex & 0xfefefe) >> 1

To make it clearer:

(corEmHex & 0x7f7f7f) << 1

If you want to have more control over how light/dark the color should be, it is best to separate the RGB values and work with them individually.

Reference of the SO en

  • Possibly based on: https://stackoverflow.com/a/1787193/1452488

  • @Andersoncarloswoss One hundred percent based on it.

  • It is always good to cite the source in these cases to recognize the work of those who drafted the answer and, also, so that users have access to all other answers that may also be useful.

  • @Andersoncarloswoss Feito.

  • Very interesting technique this.

1

Felipe I’ll give you 3 models that should help you with your answer.

1 - Various types of color scales (I think it’s as close as you want, but I couldn’t get it to work on the Stackoverflow Snippet)

https://codepen.io/stevepepple/pen/adRJaB?q=color+scaling&limit=all&type=type-pens

inserir a descrição da imagem aqui

2 - Capture the Average Color of an Image. (First you have to convert img to Base64) View in Snippet below.

    var rgb = getAverageRGB(document.getElementById('i'));
    document.body.style.backgroundColor = 'rgb('+rgb.r+','+rgb.g+','+rgb.b+')';

function getAverageRGB(imgEl) {
    
    var blockSize = 5, // only visit every 5 pixels
        defaultRGB = {r:0,g:0,b:0}, // for non-supporting envs
        canvas = document.createElement('canvas'),
        context = canvas.getContext && canvas.getContext('2d'),
        data, width, height,
        i = -4,
        length,
        rgb = {r:0,g:0,b:0},
        count = 0;
        
    if (!context) {
        return defaultRGB;
    }
    
    height = canvas.height = imgEl.naturalHeight || imgEl.offsetHeight || imgEl.height;
    width = canvas.width = imgEl.naturalWidth || imgEl.offsetWidth || imgEl.width;
    
    context.drawImage(imgEl, 0, 0);
    
    try {
        data = context.getImageData(0, 0, width, height);
    } catch(e) {
        /* security error, img on diff domain */alert('x');
        return defaultRGB;
    }
    
    length = data.data.length;
    
    while ( (i += blockSize * 4) < length ) {
        ++count;
        rgb.r += data.data[i];
        rgb.g += data.data[i+1];
        rgb.b += data.data[i+2];
    }
    
    // ~~ used to floor values
    rgb.r = ~~(rgb.r/count);
    rgb.g = ~~(rgb.g/count);
    rgb.b = ~~(rgb.b/count);
    
    return rgb;
    
}
Setting the BODY's background to the average color in the following image:

<br><br>

<img id="i" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QBKRXhpZgAASUkqAAgAAAADABoBBQABAAAAMgAAABsBBQABAAAAOgAAACgBAwABAAAAAgAAAAAAAAAAcDg5gJaYAABwODmAlpgA/9sAQwAFAwQEBAMFBAQEBQUFBgcMCAcHBwcPCwsJDBEPEhIRDxERExYcFxMUGhURERghGBodHR8fHxMXIiQiHiQcHh8e/9sAQwEFBQUHBgcOCAgOHhQRFB4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4e/8AAEQgAqgDiAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHB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tL8gTLhLlhvCjIUgKWPVdoz8/Nf33/AD+3P/f1v8acL++/5/bn/v63+NEsJR53o+nX/geQ4160IqzX3f8AB8z6S8MfF7QtB8Wa1rcPhPWpIrl7HTNPt1uLeP7Lo9su3yix37nkIBaMAA/89B1rl/BPjHRPDMei2UGj6wbLSfG765F+7gDtZeSkSJjzced8uSM7f9qvFBf33/P5cf8Af1v8aFv77P8Ax+XH/f1v8aSw1K/Xp1/4ASrVGnt93y7nqWqajptz4+t9bMlzJp63cFxKYfDtjYTIElaQqsNvP5cjfdHmO6scnPQZ73UviT4UvIPEcN7pesarZ315f3+nW91pVvBcWM9wWb91eRXYkhUsUDjZJuCdgxUfOBv77Y/+mXHb/lq3+NKL6+2n/TLj/v6f8acsLSklF32fX08hRr1YtyTW66eXqfQP/CdeDx480HxvJYeJbm60jSre3TTDZWscTXUNsYo5PtH2hyFDkMP3JIwDg4wdtfjToNvd6heweFdYuG1+bT312zvHt3jnWKGSGfEqupZyDG6tsT51yQtfMq3t55pH2ufH/XQ0i3t5hv8AS5/+/hpvDU2+v3/PsCqzj227fLufSFn8V/D0OojWfsHiiC7svFWpa9aW8EduqXaXK4jgmk8/MYPAfCSDGQM1z91440S/+GI8P6npNxeaxDaLb6fcLpsNq1j+8DNH9qiuN01sMyFYng5JG4kgGvD/ALbebW/0uf8A7+GkN7ebj/pc/T/noazWEpLv06+i7F/WKt3qvu+ffzK+qE/2ndf9dn/9CNFNkkfzG+dup70VnzM3Uj//2Q==">

Source: https://codepen.io/influxweb/pen/LpoXba

3 - Achieve a color palette from an image. Even has extension pro Chrome.

inserir a descrição da imagem aqui

Project Link on Github: https://github.com/unindented/palette-creator

Extension: https://chrome.google.com/webstore/detail/palette-creator/oolpphfmdmjbojolagcbgdemojhcnlod

Article in Portuguese to better understand how hexadecimal color works:

http://serprogramador.com.br/artigos/topico/css/Como-entender-os-padroes-de-cores-RGB-RGBA-Hexadecimal

  • Very good! I will study each item of the answer, by the way I realized that the first model that is in codepen, uses 4 external libraries jquery, lodash, Chroma and D3, must be why it didn’t work here.

  • @Felipeduarte can if that’s right, had not seen. I’ll make a model only in CSS for you to see. Sometimes it can help you too, because you will only use one color and use a ::before to make the variation.

1


Template with CSS only.

I made this model that has ONLY ONE COLOR, Just exchange it and the whole scale changes div {background: #338A2E; /* qualque cor aqui */}. The technique is to create a pseudo element in the color White or Black above the original color, and change the opacity to make the scale.

div {
height: 50px;
width: 150px;
display: inline-block;
text-align: center;
line-height: 50px;
margin-top:10px;
background: #338A2E; /* qualque cor aqui */
position: relative;
}
div::before {
    content: "";
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background-color: rgba(0, 0, 0, 0.0);
}
div:nth-child(1)::before {
    background-color: rgba(0, 0, 0, 0.1);
}
div:nth-child(2)::before {
    background-color: rgba(0, 0, 0, 0.2);
}
div:nth-child(3)::before {
    background-color: rgba(0, 0, 0, 0.3);
}
div:nth-child(4)::before {
    background-color: rgba(0, 0, 0, 0.4);
}
div:nth-child(5)::before {
    background-color: rgba(0, 0, 0, 0.5);
}
div:nth-child(6)::before {
    background-color: rgba(0, 0, 0, 0.6);
}
div:nth-child(7)::before {
    background-color: rgba(0, 0, 0, 0.7);
}
div:nth-child(8)::before {
    background-color: rgba(0, 0, 0, 0.8);
}
div:nth-child(9)::before {
    background-color: rgba(0, 0, 0, 0.9);
}
<div>0.1</div>
<div>0.2</div>
<div>0.3</div>
<div>0.4</div>
<div>0.5</div>
<div>0.6</div>
<div>0.7</div>
<div>0.8</div>
<div>0.9</div>

Now in the White

Just change the background-color: rgba(0, 0, 0, 0.1); for background-color: rgba(255, 255, 255, 0.1);

div {
height: 50px;
width: 150px;
display: inline-block;
text-align: center;
line-height: 50px;
margin-top:10px;
background: #338A2E; /* qualque cor aqui */
position: relative;
}
div::before {
    content: "";
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background-color: rgba(255, 255, 255, 0.0);
}
div:nth-child(1)::before {
    background-color: rgba(255, 255, 255,  0.1);
}
div:nth-child(2)::before {
    background-color: rgba(255, 255, 255,  0.2);
}
div:nth-child(3)::before {
    background-color: rgba(255, 255, 255,  0.3);
}
div:nth-child(4)::before {
    background-color: rgba(255, 255, 255,  0.4);
}
div:nth-child(5)::before {
    background-color: rgba(255, 255, 255,  0.5);
}
div:nth-child(6)::before {
    background-color: rgba(255, 255, 255,  0.6);
}
div:nth-child(7)::before {
    background-color: rgba(255, 255, 255,  0.7);
}
div:nth-child(8)::before {
    background-color: rgba(255, 255, 255,  0.8);
}
div:nth-child(9)::before {
    background-color: rgba(255, 255, 255,  0.9);
}
<div>0.1</div>
<div>0.2</div>
<div>0.3</div>
<div>0.4</div>
<div>0.5</div>
<div>0.6</div>
<div>0.7</div>
<div>0.8</div>
<div>0.9</div>

  • Sensational, and really right, even for problems where hexa gets too much at the ends, an algorithm would have to think a lot to identify this difference, which does not happen with a simple layer of opacity, vlw @hugocsl.

  • 1

    @Felipeduarte as I do not understand much of JS I always end up trying to solve things with CSS first rss, sometimes right, as in this case, but there are hours that is better 2 lines of JS :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.