256 RGB algorithm

Looking to generate in VB the RGB values for approximately 256 colors starting from RGB(255,255,255) to RGB(0,0,0) white to black.
BWATERSAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TSMITHCommented:
Do you mean 256 colours that best cover the spectrum?
0
BWATERSAuthor Commented:
Yes, 256 unique hues from white to black...or if you prefer, black to white.
Thanks for the reply
0
TSMITHCommented:
Since you only have 256 colours you would have to assume 6 shades of red green and blue, which gives 216 colours. Steps would be 0, 51, 102, 154, 205, and 255 in each colour. This would give you an even spectrum.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

BWATERSAuthor Commented:
True...but how would you code it in VB to generate those unique values?
0
Jan LouwerensSoftware EngineerCommented:
well, when you decide which colors you will use at each section, just loop through and ramp the colors...
c-type pseudocode example:

index 0: blue (0,0,255)
index 51: green (0,255,0)

(this loop will ramp smotthly from red to green)
for (index = 0; index < 51; index++)
{
   red = 0;
   green = 255.0 * (index / 50.0);
   blue = 255.0 - (255.0 * (index / 50.0));
}
continue for rest of colors...
0
maruzCommented:
You should better use the 3-3-2 palette.
3-3-2 means that you use 3 bits to encode intensity of red, 3 bits for green and 2 bits for blue.
You can get the values of intensities for a specific color index as:
 red = ((index AND 0xE0) / 0x20) * 255 / 7
 green = ((index AND 0x1C) / 0x04) * 255 / 7
 blue = (index AND 0x03) * 255 / 3
The bitwise AND selects the bits for appropriate color (R, G, or B), the division moves these bits down (so you get values from 0 to 7 or from 0 to 3 for blue) and the last two operations converts the value to 0-255 scale.
0
BWATERSAuthor Commented:
Very crafty...I ask for a solution in VB and I get a study in C.
I appreciate your feedback, now can you show me the code?
0
maruzCommented:
Thought you could translate it yourself. Not every graphics expert knows Visual Basic - neither do I. But I'll try my best.

Set red = ((Index And 224) / 32) * 255 / 7
Set green = ((Index And 28) / 4) * 255 / 7
Set blue = (Index And 3) * 255 / 3
0
maruzCommented:
I believe you can add a single For-cycle from 0 to 255 yourself.
0
BWATERSAuthor Commented:
I appreciate the feedback...but perhaps I'm dense or have a mental block; but I really do need a code example in VB to work from.
0
maruzCommented:
If you don't call this VB code...
0
MorFFCommented:
The 216 web-safe colours, in vb code (and keeping it simple);

1 create a new form (form1),
2 add a list box (list1),
3 add a button (command1),
4 in the command1_click event, cut-n-paste the following code;

For b = 0 To 255 Step 51
    For g = 0 To 255 Step 51
        For r = 0 To 255 Step 51
            colourval = "R:" + Format$(r, "000") + ", G:" + Format$(g, "000") + ", B:" + Format$(b, "000") + "  Hex:#" + Format$(Hex$(r), "00") + Format$(Hex$(g), "00") + Format$(Hex$(b), "00")
            List1.AddItem (colourval)
        Next r
    Next g
Next b

5 run your project
6 press the button and hey presto!
7 the listbox is populated with the rgb and hex values.

Cheers - MorFF
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MorFFCommented:
PS if you want the code explained, let me know.
0
BWATERSAuthor Commented:
Excellent, thank you!  And yes, thanks for keeping it simple...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Graphics Software

From novice to tech pro — start learning today.