简体   繁体   English

React Native 随机颜色对生成器

[英]React Native Random color pair generator

I am trying to generate a palette which would have an array of color pairs (lighter/darker) and check whether it doesn't have duplicates.我正在尝试生成一个调色板,该调色板将具有一组颜色对(较浅/较深)并检查它是否没有重复项。 I have checked Martin's color generation and several libraries like random color generator npm , but I don't quite understand how to generate a pair of similar shade colors.我检查了Martin 的颜色生成和几个库,如随机颜色生成器 npm ,但我不太明白如何生成一对相似的阴影 colors。 Taking for example these two colors:以这两个 colors 为例:

光 黑暗的

How to achieve same result but with a random color generator?如何使用随机颜色生成器获得相同的结果?

Found an answer by using Random color and Chroma js .通过使用Random colorChroma js找到了答案。 Something like this:像这样的东西:

    for (let i = 0; i < NUM_OF_COLORS; i++) {
    colorsLight[i] = randomColor({
        luminosity: "bright",
        format: "rgba",
        alpha: 0.6,
    });
    colorsDark[i] = chroma(colorsLight[i]).alpha(0.3).hex();

I generate two arrays of colors, but it can easily be put into one and used as a pair of beautiful dark/light colors.我生成了 colors 的两个 arrays,但它可以很容易地合二为一,用作一对漂亮的暗/亮 colors。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM