Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generating RGB color codes

Status
Not open for further replies.

BusMgr

IS-IT--Management
Aug 21, 2001
138
US
I have a dynamic plotting module within my database. I use it to plot sales versus state for each month. The trouble is the limited color choices.

Currently my code is
dim lngColor as long
dim j as integer

I start j at zero and increment by 10 for each loop (state). I am limited to values less then 255 by the RGB color chart. (We currently only have sales in less then 25 states)

I set lngColor = RGB(j, 128, 255-j), which returns a long value for the line method, which I then use to create my chart. The trouble is that I am looking for a 'broader' color spectrum.

Does anybody know how I can achieve a broader color spectrum?

Thanks in advance
Busmgr
 
The issue is that those RGB values regulate the intensity of each color (Red, Green, Blue). By themselves all three work on a white background but when you start combining you run into trouble.

Right now you're only varying your red and blue gong from 0 to 250, while at the same time cranking down blue from 255 to 5.

I'd say you should search the web for an RGB color chart.

One I found is:


Looking at these two you should be able to figure out a decent algorithm to get some colors out of it.
 
Thanks sostek.

I work with it a little and have settled on RGB(j, 64, 255-j)

The spectrum over my data goes from red to violet to blue, as you point out. The code returns a long value for the color (ie 16716811), not the hex equivalent from 255 to 0. I think that it might work best to generate a random color using the long value. The issue there might be that I need to be able to duplicate the color in two places in my code, and I don't know if using a random generator in vb will do that. I know in C that there are two functions, rand and random that generate random numbers differetnly; random always generating the same sequence.

Thanks again for your help and tips.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top