# Show Amstrad CPC palette and INK numbers and names
from PIL import Image, ImageDraw, ImageFont
SIZE = 500
BORDER = 20
fnt = ImageFont.truetype('/usr/share/fonts/TTF/Courier Prime.ttf', SIZE//3)
fnt2 = ImageFont.truetype('/usr/share/fonts/TTF/Courier Prime.ttf', SIZE//10)
fnt3 = ImageFont.truetype('/usr/share/fonts/TTF/IBMPlexSans-SemiBold.ttf', SIZE//1.7)
out = Image.new("RGB", (9 * SIZE, 4 * SIZE))
d = ImageDraw.Draw(out)
# CPC color layout as in the image by MacDeath on the CPCWiki forum:
# https://www.cpcwiki.eu/forum/amstrad-cpc-hardware/cpc-palette/msg53168/#msg53168
cols = (
"h000h000hh0hhh00hh000hf0fh0",
"f000f000ff0fff00ffhhhh0ff0h",
"fhhhfhhhffhfffhhfffff0hf0fh",
)
# colour names from Chapter 1, page 48 of the CPC6128 user manual:
names = (
"Black",
"Blue",
"Bright Blue",
"Red",
"Magenta",
"Mauve",
"Bright Red",
"Purple",
"Bright Magenta",
"Green",
"Cyan",
"Sky Blue",
"Yellow",
"White",
"Pastel Blue",
"Orange",
"Pink",
"Pastel Magenta",
"Bright Green",
"Sea Green",
"Bright Cyan",
"Lime Green",
"Pastel Green",
"Pastel Cyan",
"Bright Yellow",
"Pastel Yellow",
"Bright White",
)
def getcol(c):
"Convert color text to tuple"
o = []
for x in c:
if x == "h":
o.append(128)
elif x == "f":
o.append(255)
else:
o.append(0)
# based on pseudocode at https://www.grimware.org/doku.php/documentations/devices/gatearray
ink = 0
if c[0] == "f": ink += 6
if c[0] == "h": ink += 3
if c[1] == "f": ink += 18
if c[1] == "h": ink += 9
if c[2] == "f": ink += 2
if c[2] == "h": ink += 1
return tuple(o), ink
for j in range(3):
for i in range(9):
c, ink = getcol(cols[j][3 * i:3 * i + 3])
p1 = i * SIZE + BORDER, (j + 1) * SIZE + BORDER
p2 = (i + 1) * SIZE - BORDER, (j + 2) * SIZE - BORDER
p3 = p1[0], p1[1] + SIZE//3
d.rectangle((p1, p2), fill = c)
d.text(p1, "%u" % ink, font = fnt, fill = (0, 0, 0), align = "left", valign = "top", stroke_width = 15)
d.text(p1, "%u" % ink, font = fnt, fill = (255, 255, 255), align = "left", valign = "top")
d.text(p3, names[ink], font = fnt2, fill = (0, 0, 0), align = "left", valign = "top", stroke_width = 6)
d.text(p3, names[ink], font = fnt2, fill = (255, 255, 255), align = "left", valign = "top")
d.text((1.6 * SIZE, SIZE//6), "Amstrad CPC palette", font = fnt3, fill = (255, 255, 255))
out.save("Amstrad_CPC_ink_numbers_names_header_plex.png")