Create: Computing AgesBrass Docs
Reference

Colours

The 16 colours of the screens: their names, numbers, sprite digits and exact shades.

Every colour screen has the same 16 colours, the colours of Minecraft's dyes. Each colour has three spellings, used in different places:

  • a name, like "red", for term.colors and for drawing with gfx;
  • a number from 0 to 15, which the terminal functions take: term.colors.red is 14;
  • a hex digit, 0 to f, one per pixel in the sprites of gfx.image: e is red.
ColourNameNumberSprite digitShade
white00#F0F0F0
orange11#F2B233
magenta22#E57FD8
light_blue33#99B2F2
yellow44#DEDE6C
lime55#7FCC19
pink66#F2B2CC
gray77#4C4C4C
light_gray88#999999
cyan99#4C99B2
purple10a#B266E5
blue11b#3366CC
brown12c#7F664C
green13d#57A64E
red14e#CC4C4C
black15f#111111

The names are written in English, in lowercase, with an underscore: light_blue, light_gray. Watch the spelling of gray (not grey). The shades are the exact colours the screens show; black is a very dark gray, the colour of an empty screen.

Brass
local NAMES = {"white", "orange", "magenta", "light_blue", "yellow", "lime", "pink", "gray",
  "light_gray", "cyan", "purple", "blue", "brown", "green", "red", "black"}
local DARK = {[7] = true, [10] = true, [11] = true, [12] = true, [14] = true, [15] = true}
gfx.clear("black")
gfx.text(4, 6, "THE 16 COLOURS: NUMBER, SPRITE DIGIT, NAME", "white")
for n = 0, 15 do
  local x = 4 + (n % 4) * 76
  local y = 20 + (n // 4) * 38
  gfx.rect(x, y, 72, 34, n, true)
  if n == 15 then gfx.rect(x, y, 72, 34, "gray") end
  local ink = "black"
  if DARK[n] then ink = "white" end
  gfx.text(x + 4, y + 4, tostring(n), ink, 2)
  gfx.text(x + 62, y + 4, string.format("%x", n), ink)
  gfx.text(x + 4, y + 24, NAMES[n + 1], ink)
end
Screen
Screen

In the terminal: numbers

term.set_fg (the text) and term.set_bg (the cells behind it) take a number. Write it with term.colors, which is easier to read than the number itself:

Brass
term.set_fg(term.colors.orange)
print("Furnace lit")
term.set_fg(term.colors.white)
print(term.colors.red, term.colors.black)
Screen
Furnace lit
14  15

A name is not accepted there, and neither is a number outside 0 to 15:

Brass
term.set_fg("red")
Screen
snippet:1: bad argument #1 to 'set_fg' (number expe
cted, got string)

term.set_fg(16) stops with bad argument #1 to 'set_fg' (color must be 0..15). See term.

In drawings: names or numbers

Every function of gfx takes a name ("red"), a number (14) or term.colors.red: all three are the same colour. The special name "none" (or the number -1) erases, leaving the pixel empty. An unknown name stops the program with an error that lists the 16 names and none.

gfx.get_pixel always answers with a number. To turn it back into a name, keep the names in a list in the order of the table: the name of colour n is at index n + 1.

Brass
local NAMES = {"white", "orange", "magenta", "light_blue", "yellow", "lime", "pink", "gray",
  "light_gray", "cyan", "purple", "blue", "brown", "green", "red", "black"}
gfx.rect(1, 1, 10, 10, "cyan", true)
print(NAMES[gfx.get_pixel(5, 5) + 1])
Screen
cyan

In sprites: hex digits

gfx.image draws a list of strings, one character per pixel. The character is the number of the colour written in hexadecimal: 0 to 9, then a (10) to f (15), capitals accepted. Any other character, usually ., leaves the pixel as it is.

Brass
local sprite = {
  "0123",
  "4567",
  "89ab",
  "cdef",
}
gfx.clear("black")
gfx.rect(9, 9, 66, 66, "white")                  -- a frame, to see the black pixel
gfx.image(10, 10, sprite, 16)
gfx.rect(99, 9, 194, 14, "white")
gfx.image(100, 10, {"0123456789abcdef"}, 12)
gfx.rect(100, 40, 192, 12, "yellow", true)       -- a yellow strip under the next sprite
gfx.image(100, 40, {"e.e.e.e.e.e.e.e."}, 12)
gfx.text(100, 58, "DOTS LEAVE THE PIXEL UNTOUCHED", "white")
Screen
Screen

Screens without colours

Not every screen shows the 16 colours:

ScreenText and cell coloursDrawing (gfx)
Personal Computer, Microcontroller, Modern Computershownshown
Transistor Mainframe (green), Minicomputer (amber)ignored: every character glows in the phosphor colour on a dark screenevery colour except black lights up in the phosphor colour; black stays dark
Tube Computer (teletype)ignored: dark ink on paperno gfx
LCD Monitor, on any computershownshown
CRT Monitoras on the computer's own screen (the teletype's paper becomes green phosphor)as on the computer's own screen

The computer always remembers the colours a program chose; only the screen decides whether to show them. An LCD Monitor placed against a Transistor Mainframe shows them all. The same palette on the amber screen of a Minicomputer:

Brass
local NAMES = {"white", "orange", "magenta", "light_blue", "yellow", "lime", "pink", "gray",
  "light_gray", "cyan", "purple", "blue", "brown", "green", "red", "black"}
local DARK = {[7] = true, [10] = true, [11] = true, [12] = true, [14] = true, [15] = true}
gfx.clear("black")
gfx.text(4, 6, "THE 16 COLOURS: NUMBER, SPRITE DIGIT, NAME", "white")
for n = 0, 15 do
  local x = 4 + (n % 4) * 76
  local y = 20 + (n // 4) * 38
  gfx.rect(x, y, 72, 34, n, true)
  if n == 15 then gfx.rect(x, y, 72, 34, "gray") end
  local ink = "black"
  if DARK[n] then ink = "white" end
  gfx.text(x + 4, y + 4, tostring(n), ink, 2)
  gfx.text(x + 62, y + 4, string.format("%x", n), ink)
  gfx.text(x + 4, y + 24, NAMES[n + 1], ink)
end
Screen
Screen

On these screens, only black and "not black" count: black text on a lit block disappears, and so do the white labels here, drawn on blocks that are lit too. For a program meant for them, draw in black and one other colour.

Choosing colours

A few habits make screens easier to read, in a dark factory as on a sunny monitor wall:

  • keep the meaning of a colour the same everywhere: lime or green for running and full, yellow or orange for low or busy, red for stopped, empty or overloaded;
  • write dark text (black) on light colours (white, yellow, lime, light_blue, pink...) and white text on dark ones (gray, blue, purple, brown, red, black);
  • do not rely on colour alone: add a word (OK, LOW, STOP), so that the screen still works on a Transistor Mainframe and for colour-blind players.

See Screens and monitors for the layout of a whole screen.