This site requires JavaScript, please enable it in your browser!
Greenfoot back
pickles22
pickles22 wrote ...

2014/4/23

The Colors Greenfoot Looks For

pickles22 pickles22

2014/4/23

#
I am needing to know the hexadecimal value of pink, gray, dark gray, light gray, and orange that greenfoot knows, so i can add it to a Actor in my game. if you know eithor the hexadecimal value or the RGB value that would be greatly appreciated.
danpost danpost

2014/4/23

#
You can use the Color class methods, 'getRed', 'getGreen' and 'getBlue', on the color to get those values (in decimal).
pickles22 pickles22

2014/4/24

#
would i have to create a new integer such as
public int pinkRed = Color.PINK.getRed
just to get the red value used in pink
danpost danpost

2014/4/24

#
As I am not clear as to how you are to 'add it to a Actor in my game', I cannot say whether it would need to be an instance field (with the 'public' modifier) or just a variable local to the method (or constructor) you acquire the value in. If your actor is to be changing colors throughout its existence, then you will want them as instance fields (as you show above). Since the values are constant, you could just hard-code them in your statements (unless you are instructed to get those values by way of code). The RGBs for each determined by, as an example,
System.out.println(java.awt.Color.pink.toString());
are as follows: PINK: red=255; green=175; blue=175; GRAY: red=128; green=128; blue=128; DARKGRAY: red=64; green=64; blue=64; LIGHTGRAY: red=192; green=192; blue=192; ORANGE: red=255; green=200; blue=0;
danpost danpost

2014/4/24

#
danpost wrote...
If your actor is to be changing colors throughout its existence, then you will want them as instance fields (as you show above).
As an alternative, you can save the colors themselves and get the individual color parts when you need them; so, instead of saving 15 color part values, you are saving 5 colors from which you can retrieves those color part values from. You may not even have to save the colors. It really depends on how you are using them. You may, just for the sake of readability, rather go ahead and save all 15 color part values. However, the more you rely on your own coding, the more chance of an error creeping in. I, myself, would prefer to get the actual value from the color at the time I need it.
You need to login to post a reply.