ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating Random Colors

Solved!
Go to solution

Just out of curiosity - I'm trying to make a string display random colors. My understanding is text.textcolor accepts a hex number in the format "RRGGBB". I"m doing the following, but I'm not sure that this is right. Can someone check and let me know?

 

Much appreciated.

 

LB 

0 Kudos
Message 1 of 5
(7,386 Views)

Hello LB,

 

If you're looking for a truly random color, there is no need to build the RGB components individually.  You can just generate a random integer within the color range you want to use, valid numbers should be 0-16777215 (decimal), 16777216 is used for transparent objects but can't be used for text.

 

Regards,

Tom L.
0 Kudos
Message 2 of 5
(7,363 Views)
Solution
Accepted by LeroyBogz

You need to create a binary 24-bit number to give the color. Labview provides a VI (RGB to Color.vi) to create a color based on 3 8-bit numbers in the sub-palette Graphics & Sounds / Picture functions. See below

 

Example_VI_BD.png

Marc Dubois
0 Kudos
Message 3 of 5
(7,355 Views)

Of course you really don't need three random numbers.

Example_VI_BD.png


"Should be" isn't "Is" -Jay
Message 4 of 5
(7,338 Views)

Old thread, but in some case you will face the problem where you cannot distinguish the background color and the text color.

Here is a VI that helps...

https://lavag.org/files/file/301-55-easily-distinguishable-colorvi/

 

Benoit

0 Kudos
Message 5 of 5
(6,493 Views)