Skip to content

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.

tick 0
Sensor0
=
in
Unpack Color1
= unpack
Operation2
=
Operation3
=
Operation4
=
Operation5
=
Operation6
=
Operation7
=
Print8
Print9
Print10
Print11
Print12
Print13
Print Flush14
Stop15
@counter0number
colournullnull
Rnullnull
Gnullnull
Bnullnull
Anullnull

The program asks copper for its colour and prints it channel by channel: the board shows copper colour: 217 157 115.

sensor colour @copper @color
unpackcolor 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

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 colour
op div R R 2
op div G G 2
op div B B 2
packcolor dim R G B A

That 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.