Search code examples
algorithmcolors

Algorithm to randomly generate an aesthetically-pleasing color palette


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.

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.

Any ideas would be great.


Solution

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

    (example in 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;
    }
    

    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:

    First

    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:

    Second

    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.

    Some additional resources: