Pages: [1]   Go Down
Author Topic: Random RGB Values Give Pastel Colors  (Read 1276 times)
0 Members and 1 Guest are viewing this topic.
Manchester, NH
Offline Offline
Full Member
***
Karma: 0
Posts: 116
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have some RGB LEDS in a strip and looking to create some random colors for a background effect. When I calculate three random numbers say from 1 to 50 (so they're not too bright) then set the R, G, and B LEDS to those values I get different colors but they're always pastel and never vivid.

Is there a way to process the random numbers somehow to weight them toward more vivid colors, maybe pick numbers from 1 to 255 then scale them down to reduce brightness?

Would I have better luck to create an array of RGB numbers for colors that I want and just randomly step around the array?
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 178
Posts: 8064
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Unless one of the three colors is 0 you will not get vivid colors. Any amount of brightness shared by all three will come out as white mixed with your color.  For example 50R/50G/0B is bright yellow but 50R/50G/30B is pastel yellow.

You could pick three random values and then randomly pick one of the three to set to 0.

0R/50G/30B = Greenish Blue
50R/0G/30B = Reddish Purple
50R/50G/0B = Bright Yellow
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Manchester, NH
Offline Offline
Full Member
***
Karma: 0
Posts: 116
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Great idea... and I like the idea of randomly altering random numbers!
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4545
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Great idea... and I like the idea of randomly altering random numbers!

You could use HSV color model, not RGB color model. Random 'hue' will always be saturated.
Logged

No, I don't answer questions sent in private messages...

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 508
Posts: 31382
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
You could pick three random values and then randomly pick one of the three to set to 0.
You can also pick one to be randomly 255 as well.
The other way is to jay use the top two bits of each component.
In truth there are not all that many vivid colours anyway.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 178
Posts: 8064
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
You could pick three random values and then randomly pick one of the three to set to 0.
You can also pick one to be randomly 255 as well.
The other way is to jay use the top two bits of each component.
In truth there are not all that many vivid colours anyway.

Picking one to be 255 would not help.  Changing  250R/200G/200B to 255R/200G/200B would only get you a slightly more intense pale pink.  Changing to 0R/200G/200B, 250R/0G/200B or 250R/200G/0B would get Cyan, Purple, and Yellow, respectively.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 508
Posts: 31382
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Picking one to be 255 would not help.
Yes it does, have you tried it? It allows secondary colours which can be vivid.
Logged

Offline Offline
Sr. Member
****
Karma: 7
Posts: 264
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Mike is correct, it does help  smiley-wink

This trippylighting.com ( scroll down to the video) does exactly that. It randomly chooses 3 values and then clamps one of them to 255 and then fades from the last set of randomly chosen values to the new set.
Logged


Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4545
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In truth there are not all that many vivid colours anyway.

1536 of them in the HSV model with 256 values for RGB.
Logged

No, I don't answer questions sent in private messages...

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 178
Posts: 8064
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In truth there are not all that many vivid colours anyway.
1536 of them in the HSV model with 256 values for RGB.
Or 36,001 if Hue is 0-359 degrees and Value is 0 to 100% (Saturation is 100%).

http://www.csgnetwork.com/csgcolorsel4.html

250R/200G/200B = 0°H/20%S/98%V

Inserting 255 in one position:
255R/200G/200B = 0°H/22%S/100%V
250R/255G/200B = 65°H/22%S/100%V
250R/200G/255B = 295°H/22%S/100%V
In all three cases the saturation value is only 22%, very pastel.

Inserting 0 in one position:
0R/200G/200B = 180°H/100%S/78%V
250R/0G/200B = 312°H/100%S/98%V
250R/200G/0B = 48°H/100%S/98%V
In all three cases the saturation value is 100%, quite vivid.

Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

texas
Offline Offline
God Member
*****
Karma: 27
Posts: 862
old, but not dead
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I had the best results with nice colors by only lighting two LEDs at a time.  If you ramp the PWM up and then down by 1, while overlapping with the next color(R&G, G&B, B&R) by 180 degrees, you get a rainbow of vivid colors.  Any illumination of the third LED will just make the color lose saturation.
Logged

Experience, it's what you get when you were expecting something else.

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4545
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I had the best results with nice colors by only lighting two LEDs at a time.  If you ramp the PWM up and then down by 1, while overlapping with the next color(R&G, G&B, B&R) by 180 degrees, you get a rainbow of vivid colors. 

That's the 'H' part of HSV.

Any illumination of the third LED will just make the color lose saturation.

And that's the 'S' part.
Logged

No, I don't answer questions sent in private messages...

Offline Offline
Sr. Member
****
Karma: 7
Posts: 264
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I actually have to revise what I had stated earlier. Clamping one of the values to 255 is not going to work. The way the rings are generated in my lighting system is that the optics in fromt of the LED head " clamps" one of the colors to zero.
So in essence if your algorithm chooses one of the three channels to clamp to zero and then you choose values randomly for the other two channels it'll work better.

However, the approach fungus has posted, selectin HSV and conveting it to RGB - while more complicated to implement and more computationally expensive - is by far the best approach!
Logged


Pages: [1]   Go Up
Jump to: