Colour and transparency
Colour is a state, not a property of a shape: choose it once and it holds until the next time
Three squares, each set a different way. The red one is opaque, the green one is half transparent, and the blue one is taken as a ready number.
color: four numbers from 0 to 255
Section titled “color: four numbers from 0 to 255”draw color 255 180 60 255Red, green, blue and opacity: 255 is fully solid, 0 is invisible, 128 lets whatever was drawn earlier show through.
| What is set | Field | Range |
|---|---|---|
| red | first | 0–255 |
| green | second | 0–255 |
| blue | third | 0–255 |
| opacity | fourth | 0–255 |
A fractional number drops its fraction: 180.9 is 180.
The colour holds until it is changed
Section titled “The colour holds until it is changed”Colour is not a property of a shape but a state of the display. Set color and every shape
that follows is that colour, be it one or twenty.
draw color 255 60 60 255draw rect 10 10 40 40draw rect 60 10 40 40draw rect 110 10 40 40Three red squares, one color. That is also the trap: forget to change the colour before the
second picture and it is drawn in the first one’s colour.
col: a colour as one number
Section titled “col: a colour as one number”packcolor colour 0.2 0.5 1 0.6draw col colourcol takes one number with all four channels packed into it. The number itself is prepared
by the packcolor instruction, whose shares run not to 255 but from zero to one.
draw color |
draw col |
|
|---|---|---|
| how many fields | four | one |
| channels | 0–255 | 0–1 (through packcolor) |
| when it is handier | when the colour is written into the program | when the colour is in a variable or came from somewhere |
A packed colour is an ordinary number, and it can be treated as one: kept in a memory cell,
passed to a neighbouring processor, chosen with select out of two prepared ones.
Transparency draws over, it does not pre-mix
Section titled “Transparency draws over, it does not pre-mix”A half-transparent shape mixes with what is already drawn on the display. So the order of commands decides everything: background first, then what goes on top.
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.