Create a hexadecimal colour based on a string with JavaScript

后端 未结 13 916
旧时难觅i
旧时难觅i 2020-11-30 17:15

I want to create a function that will accept any old string (will usually be a single word) and from that somehow generate a hexadecimal value between #000000

13条回答
  •  攒了一身酷
    2020-11-30 18:12

    I have opened a pull request to Please.js that allows generating a color from a hash.

    You can map the string to a color like so:

    const color = Please.make_color({
        from_hash: "any string goes here"
    });
    

    For example, "any string goes here" will return as "#47291b"
    and "another!" returns as "#1f0c3d"

提交回复
热议问题