Skip to content

Colour and transparency

Colour is a state, not a property of a shape: choose it once and it holds until the next time

mediumYou need: The first picture, Arithmetic
tick 0
Draw0
rgb
Draw1
rgb
a
Draw2
xy
widthheight
Draw3
rgb
a
Draw4
xy
widthheight
Pack Color5
= pack
Draw6
color
Draw7
xy
widthheight
Draw Flush8
Stop9
@counter0number
colournullnull

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.

draw color 255 180 60 255

Red, 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.

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 255
draw rect 10 10 40 40
draw rect 60 10 40 40
draw rect 110 10 40 40

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

packcolor colour 0.2 0.5 1 0.6
draw col colour

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