Color generator

Asked

Viewed 688 times

3

I want to develop a generator of random colors but that are clear, that is, it is possible to read a text with black color on the color generated randomly.
Random colors I can generate using the following code:
RGB(RandomRange(0,255), RandomRange(0,255), RandomRange(0,255));

The question is: How to generate only light colors?

1 answer

10


A very simple way is this:

RGB(RandomRange(150,255), RandomRange(150,255), RandomRange(150,255));

Basically you’re making the minimum color 150, 150, 150.

The higher the value, the lighter the colors become. If you only wanted dark colors, it would be the other way around:

RGB(RandomRange(0,150), RandomRange(0,150), RandomRange(0,150));

In both cases, adjust the 150 in all entries according to your preference.

If you want bright colors, it pays to use variables instead of 150, and create a formula that divides a number only between R G and B, maintaining the ratio but allowing "overload" one of them if the other is dark.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.