Question about coloring pixels

I was wondering how I go about translating rgb color data into a number that can be used for an array of pixels.

For instance


for (int i = 0; i < pixels.length; i++) {
     pixels[i] = Color.get(random.nextInt(255), random.nextInt(255), random.nextInt(255));
//                         RED                  BLUE                 GREEN
}

So, my question to you guys: what should the Color.get() method actually do to turn the three values into one, usable value?

Thanks,
| Nathan

Is this your Color class or an existing one? For an existing one, why not just pull up the source and find out?

Otherwise, you need to learn about how ints are represented in binary, and how colors are typically packed into ints. There are many many such encodings, but a typical one is RGBA, where the most significant byte in the int is the red component, followed by Green, Blue, then Alpha at the least significant byte.

http://www.khanacademy.org/science/computer-science/v/binary-numbers

When you’ve watched that, go here next:

Thanks! I’ll look into both of those right away.

This is just something new I want to play around with after looking into the Minicraft source code.

| Nathan

I wrote a post a while back about understanding RGB here.

I also wrote a simplified post for bitwise operations here.