随机生成美观调色板的算法 [英] Algorithm to randomly generate an aesthetically-pleasing color palette

查看:21
本文介绍了随机生成美观调色板的算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种简单的算法来生成大量随机的、美观的颜色.所以没有疯狂的霓虹色,让人联想到粪便的颜色等.

I'm looking for a simple algorithm to generate a large number of random, aesthetically pleasing colors. So no crazy neon colors, colors reminiscent of feces, etc.

我已经找到了解决此问题的方法,但它们依赖于替代 RGB 的调色板.我宁愿直接使用 RGB 而不是来回映射.这些其他解决方案也最多只能生成 32 种左右的令人愉悦的随机颜色.

I've found solutions to this problem but they rely on alternative color palettes than RGB. I would rather just use straight RGB than mapping back and forth. These other solutions also can at most generate only 32 or so pleasing random colors.

任何想法都会很棒.

推荐答案

您可以将随机颜色的 RGB 值与恒定颜色的 RGB 值进行平均:

You could average the RGB values of random colors with those of a constant color:

(Java 示例)

public Color generateRandomColor(Color mix) {
    Random random = new Random();
    int red = random.nextInt(256);
    int green = random.nextInt(256);
    int blue = random.nextInt(256);

    // mix the color
    if (mix != null) {
        red = (red + mix.getRed()) / 2;
        green = (green + mix.getGreen()) / 2;
        blue = (blue + mix.getBlue()) / 2;
    }

    Color color = new Color(red, green, blue);
    return color;
}


将随机颜色与白色 (255, 255, 255) 混合,通过增加亮度同时保持原始颜色的色调来创建中性粉彩.这些随机生成的粉彩通常搭配得很好,尤其是在数量众多的情况下.


Mixing random colors with white (255, 255, 255) creates neutral pastels by increasing the lightness while keeping the hue of the original color. These randomly generated pastels usually go well together, especially in large numbers.

以下是使用上述方法生成的一些柔和的颜色:

Here are some pastel colors generated using the above method:


您还可以将随机颜色与恒定的柔和色混合,从而产生一组有色的中性色.例如,使用浅蓝色可以创建如下颜色:


You could also mix the random color with a constant pastel, which results in a tinted set of neutral colors. For example, using a light blue creates colors like these:


更进一步,您可以向生成器添加启发式方法,将互补色或阴影级别考虑在内,但这一切都取决于您希望通过随机颜色获得的印象.


Going further, you could add heuristics to your generator that take into account complementary colors or levels of shading, but it all depends on the impression you want to achieve with your random colors.

一些额外的资源:

这篇关于随机生成美观调色板的算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆