Color swatches

a pcture of color swatch files.
Ooh colors.

Ok, now I don't know where I got rgb.txt. It might not be shipped with modern Linuxes. if you don't have it on your computer, you can find it online. Here are the first few lines of my copy:

! $Xorg: rgb.txt,v 1.3 2000/08/17 19:54:00 cpqbld Exp $
255 250 250		snow
248 248 255		ghost white
248 248 255		GhostWhite

Update June 19, 2025: The script has been modified to work with alternative color definition files.

Here is the script that generates color swatches:

#!/usr/bin/env python3
"""Generate all X11 colors described in /etc/X11/rgb.txt
"""
import os
import re
import sys

USAGE="""Usage: x11colors.py [-h|--help] [-d|--dry-run] [FILE]

 Generate all X11 colors described in /etc/X11/rgb.txt
 Makes 64x64px png files, a lot of them.
 Requires the Imagemagick "convert" program.

 The optional FILE argument may be provided to
 specify an alternative color definition file.

 Options:
   -h,--help     Print help message.
   -d,--dry-run  Print what would be done.
 """

DRY_RUN=False

def shell(cmd):
	print(cmd)
	if not DRY_RUN:
		if 0!=os.system(cmd):
			raise Exception(cmd)

def main(argv=None):
	argv=argv or sys.argv
	opts=[arg for arg in argv if     arg.startswith('-')]
	args=[arg for arg in argv if not arg.startswith('-')]

	if "-h"     in opts\
	or "--help" in opts:
		print(USAGE)
		return 0
	if "-d"        in opts\
	or "--dry-run" in opts:
		global DRY_RUN
		DRY_RUN=True

	color_file="/etc/X11/rgb.txt"
	if len(args)>1:
		color_file=args[1]
	print("#",color_file)

	with open(color_file) as file:
		for line in file.readlines():
			if line.startswith("!"):
				continue
			ss=line.split()
			r=ss[0]
			g=ss[1]
			b=ss[2]
			color="-".join(ss[3:])

			cmd=re.sub(r'\t+',' ',
				f"convert \
				-size 64x64 \
				xc:rgba\\({r},{g},{b},1.0\\) \
				{color}.png ;")
			shell(cmd)
	return 0

if __name__ == "__main__":
	sys.exit(main())

So, I would have written the cmd all on one line, but if I did that, then the text would overflow (on the webpage! also, turn your phone sideways!). I also want to point out that I (a human) wrote this. You might be able to get the AI to generate something like this, but it won't have any style.

So, it turns out that there is quite a history of the rgb.txt file. There are also some other color lists out there. You can find out more at:

https://people.csail.mit.edu/jaffer/Color/Dictionaries

There are some alternative color definition files there too.

So, yeah, I did this and it changed my life.