This question already has an answer here:
I wanted to make a color picker in java, but at the moment it isn't really working out, so I looked up on youtube how I can generate pixels with all kind of colors. I found this code and I wanted to ask what it means, so I can move on and really learn something from it. This is the code:
int a = (int)(Math.random()*256); //alpha
int r = (int)(Math.random()*256); //red
int g = (int)(Math.random()*256); //green
int b = (int)(Math.random()*256); //blue
int p = (a<<24) | (r<<16) | (g<<8) | b; //pixel
I think that those ints (argb) just generate a random number that's between 0 and 256, but I don't know what that int p does, if you can explain that to me. that'd be awesome!
Aucun commentaire:
Enregistrer un commentaire