Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38979
| From | Andreas Leitgeb <avl@logic.at> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Game color question, with max 256 colors |
| Date | 2019-06-02 14:16 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <slrnqf7mh6.cfl.avl@logic.at> (permalink) |
| References | <qcv1ae$1670$1@gioia.aioe.org> |
Graeme Geldenhuys <graemeg@example.net> wrote:
> Is there anybody here that can figure this out?
> public class Color {
> public static int get(int a, int b, int c, int d) {
> return (get(d) << 24) + (get(c) << 16) + (get(b) << 8) + (get(a));
> }
This method encodes 4 unsigned 1-byte values in an int. Probably these
4 values are the 4 separate colors to be used for rendering the sprite.
Encoding 4 values into one means that the caller only needs to pass
one value for all four colors. In a serious application, one would use
a class to hold the four independent color attributes.
> public static int get(int d) {
> if (d < 0) return 255;
> int r = d / 100 % 10;
> int g = d / 10 % 10;
> int b = d % 10;
> return r * 36 + g * 6 + b;
> }
> }
This method converts values from a "fake base-6" representation
into a binary representation of a "6-shades of each red,green,blue
colorcube."
E.g.:
555: 5 red, 5 green, 5 blue - decimal value 5*36 + 5*6 + 5 = 215
432: 4 red, 3 green, 2 blue - decimal value 4*36 + 3*6 + 2 = 164
-1 is a special case here, and is encoded as 255, which likely
gets a special treatment lateron. Maybe it means transparent,
but I don't know, without looking up the relevant part of the
source to see how screen.render(...) unpacks and uses the
values. That the digits would mean red,green,blue in this order
is just a guess, based on how colors are usually specified.
> screen.render(... , Color.get(-1, 555, 555, 555), 0);
> https://www.twitch.tv/videos/38122415
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Game color question, with max 256 colors Graeme Geldenhuys <graemeg@example.net> - 2019-06-02 00:21 +0100
Re: Game color question, with max 256 colors Andreas Leitgeb <avl@logic.at> - 2019-06-02 14:16 +0000
Re: Game color question, with max 256 colors Graeme Geldenhuys <graemeg@example.net> - 2019-06-05 17:53 +0100
csiph-web