Using bitwise operators to create a gradient

Hi all,
I have a starting colour:

int col = 0xFF000000;

And I’m trying to create a loop that increases that colour to 0xFF111111 and then 0xFF222222 and so on. Is there an easier way of doing this with bitwise operators than doing it manually?

Thanks in advance

Paul

How are you rendering?

Why do you need the step size to be so particular? (to be exact, 17 bytes)

Why not just increment RGB values gradually to produce a smooth gradient?

I’m putting the pixel straight into a bufferedimage with setRGB. I’m just trying to loop through and change that colour to one grade high each time.

How about;


		for (int i=0;i<16;i++)
		{
		    int col=0xFF000000;
		    for (int j=0;j<24;j+=4)
		    {
		        col|=(i<<j);
		    }
		    System.out.println(Integer.toHexString(col));
		}


Ah, that’s exactly what I wanted. :slight_smile: Thanks!