import subprocess
import sys
NOTES = ["♪", "♫", "♩", "◆"]
DIM_COLORS = ["#3C1450", "#143C50", "#501432"] PERIOD = 37
CELL_W, CELL_H = 20, 40
FONT_SIZE = 26
OUT = sys.argv[1] if len(sys.argv) > 1 else "static/img/note-field.png"
def font():
listing = subprocess.run(
["fc-list", ":charset=266a 266b 2669 25c6", "file"],
capture_output=True, text=True, check=True,
).stdout
files = [l.split(":")[0].strip() for l in listing.splitlines() if l.strip()]
for preferred in ("NotoSansMonoCJK", "NotoSansCJK", "DejaVuSans"):
for f in files:
if preferred in f:
return f
if not files:
sys.exit("no font on this system has all four glyphs")
return files[0]
def main():
args = ["magick", "-size", f"{PERIOD * CELL_W}x{PERIOD * CELL_H}", "xc:none",
"-font", font(), "-pointsize", str(FONT_SIZE), "-gravity", "none"]
drawn = 0
for y in range(PERIOD):
for x in range(PERIOD):
h = (x * 7 + y * 13) & 0xFFFFFFFF
if h % PERIOD:
continue
glyph = NOTES[(h // PERIOD) % len(NOTES)]
colour = DIM_COLORS[(h // PERIOD + 1) % len(DIM_COLORS)]
args += ["-fill", colour,
"-annotate", f"+{x * CELL_W + 2}+{y * CELL_H + CELL_H - 12}", glyph]
drawn += 1
args += ["-strip", OUT]
subprocess.run(args, check=True)
print(f" {OUT}: {drawn} notes in a {PERIOD}x{PERIOD} cell tile")
if __name__ == "__main__":
main()