Unpack Color
The other side of packcolor: one number becomes four again
A packed colour is one number, and it cannot be read by eye. unpackcolor lays it back out
into four channels.
The program asks copper for its colour and prints it channel by channel: the board shows
copper colour: 217 157 115.
sensor colour @copper @colorunpackcolor R G B A colour| Field | What is in it |
|---|---|
| the first four | where to put red, green, blue and alpha |
| fifth | the packed colour |
Why take a colour apart
Section titled “Why take a colour apart”Taking one apart is rarely needed for its own sake — colours are usually assembled rather than read. There is one real use: learning a colour somebody else chose.
- an item’s, liquid’s or block’s colour —
sensor @color, and the display draws ore in its own colour; - a team’s colour —
sensor @color @crux, so markers on the map match what the player sees around them; - a colour that arrived from a memory cell or a neighbouring processor and needs a small change — dimming it by halving the channels and packing it back, for instance.
unpackcolor R G B A colourop div R R 2op div G G 2op div B B 2packcolor dim R G B AThat is the usual way of working with colour: take apart, adjust the channels, pack again. The packed number itself must not be touched with arithmetic.
Unofficial fan project, not affiliated with Anuke. Mindustry sprites, fonts and translations © Anuke, used under GPL-3.0; Fira Code under OFL-1.1. Site code is GPL-3.0.