Pack Color
A colour made of four numbers is awkward to carry around. packcolor folds it into one — and the colour becomes an ordinary value
draw color takes a colour as four numbers, and while a program has one colour that is enough.
As soon as there are several and they have to be chosen between, four numbers turn into four
variables that get dragged around together. packcolor folds them into one.
packcolor red 1 0 0 1draw col red| Field | What is in it |
|---|---|
| first | where to put the finished colour |
| the other four | red, green, blue and alpha |
A colour becomes an ordinary value
Section titled “A colour becomes an ordinary value”This is what it is all for: the colour is now one number, and one number can do everything
any other number can. Go into a memory cell. Be chosen with select. Be passed to
a neighbouring processor. Here the program chooses between an alarm colour and a calm one in
a single line:
select colour lessThan stock 50 alarm calmdraw col colourThrough draw color the same thing would need a branch and four assignments in each branch.
A number not meant to be read
Section titled “A number not meant to be read”Look at the variables table: red there holds not a round value but something like 2.1e-314.
That is as it should be.
A packed colour is a colour’s bytes placed inside a number, not a number in the usual sense. To the game it is simply a way of carrying four bytes in one value.
Where else such numbers come from
Section titled “Where else such numbers come from”Items, liquids, blocks and teams have colours of their own, and sensor gives them in the same
packed form:
sensor colour @copper @colordraw col colourThat is how an item is drawn on a display in its own colour — without writing out by hand that copper is orange.
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.