Generate Random Color distinguishable to Humans

前端 未结 9 921
旧时难觅i
旧时难觅i 2020-12-12 14:11

I am trying to randomly generate a color in hex in javascript.

However the colors generated are almost indistinguishable from eachother.
Is there a way to improv

9条回答
  •  情深已故
    2020-12-12 15:10

    First of all, why are you building hex values from strings? Just use numbers for the values, then output with something like yourNumber.toString(16).

    Then, to make the colours more distinct, don't use the full range of 0 to 255 for each colour component, but maybe go in jumps of 10, or 20, or whatever you need to generate wide enough differences.

提交回复
热议问题