yiq

Color Gen JS Example - RandomRGB

Code

            
<div id="target" style="width: 100%; height: 100px; text-align: center; font-size: 25px;"></div>
<script src="../../../dist/colorgen.js"></script>
<script>
    let tar = document.getElementById("target");
    function go(){
        let color = colorgen.randomRGB();
        let background = colorgen.yiq(color) ? "#101010" : "#fefefe";
        let border = !colorgen.yiq(color) ? "#101010" : "#fefefe";
        let hexc = colorgen.to24BitRGB(color).toString(16);
        while (hexc.length < 6) hexc = "0" + hexc;
        tar.style.color = "#" + hexc;
        tar.style.backgroundColor = background;
        tar.style.border = "solid 5px " + border;
        tar.innerHTML = "Click <br> to <br> change"
    }
    go();
    tar.onclick = go;
</script>
            
        

Result