Skip to content

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.

tick 0
Pack Color0
= pack
Pack Color1
= pack
Draw2
rgb
Draw3
color
Draw4
xy
widthheight
Draw5
color
Draw6
xy
widthheight
Draw Flush7
Print8
Print Flush9
Stop10
@counter0number
rednullnull
bluenullnull
packcolor red 1 0 0 1
draw col red
Field What is in it
first where to put the finished colour
the other four red, green, blue and alpha
tick 0
Pack Color0
= pack
Pack Color1
= pack
Set2
=
Select3
= if
then else
Draw4
rgb
Draw5
color
Draw6
xy
widthheight
Draw Flush7
Stop8
@counter0number
alarmnullnull
calmnullnull
stocknullnull
colournullnull

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 calm
draw col colour

Through draw color the same thing would need a branch and four assignments in each branch.

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.

Items, liquids, blocks and teams have colours of their own, and sensor gives them in the same packed form:

sensor colour @copper @color
draw col colour

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