From e03dfd3b813929067e5b5c30752e336ea2be1f70 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Sun, 11 Feb 2024 11:34:58 +0100 Subject: Start writing a colour chart --- forms/chart_data/amanda.yaml | 150 +++++++++++++++++++++++++++++++++++++++++++ forms/colour_chart.py | 72 +++++++++++++++++++++ 2 files changed, 222 insertions(+) create mode 100644 forms/chart_data/amanda.yaml create mode 100755 forms/colour_chart.py (limited to 'forms') diff --git a/forms/chart_data/amanda.yaml b/forms/chart_data/amanda.yaml new file mode 100644 index 0000000..ee0c7ec --- /dev/null +++ b/forms/chart_data/amanda.yaml @@ -0,0 +1,150 @@ +title: "Amanda 100% silk" +colours: + - label: "4000" + bg: 0 0 0 + - label: "2000" + bg: 255 255 255 + - label: "3000" + bg: 222 218 211 + - label: "0115" + bg: 214 176 55 + - label: "0118" + bg: 213 151 11 + - label: "0892" + bg: 220 159 42 + - label: "0121" + bg: 209 126 7 + - label: "0122" + bg: 234 128 11 + - label: "1334" + bg: 227 104 45 + - label: "0450" + bg: 216 44 14 + - label: "0790" + bg: 201 10 9 + - label: "0501" + bg: 196 14 20 + - label: "0503" + bg: 174 4 13 + - label: "0504" + bg: 155 30 34 + - label: "0105" + bg: 135 3 12 + - label: "0918" + bg: 106 6 16 + - label: "0917" + bg: 143 25 32 + - label: "1400" + bg: 202 27 33 + - label: "1391" + bg: 204 29 43 + - label: "0104" + bg: 217 49 37 + - label: "0081" + bg: 230 190 181 + - label: "0075" + bg: 224 164 156 + - label: "0637" + bg: 198 131 123 + - label: "0638" + bg: 186 103 102 + - label: "0916" + bg: 183 91 84 + - label: "0284" + bg: 165 112 111 + - label: "0163" + bg: 215 174 175 + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: + - label: "" + bg: diff --git a/forms/colour_chart.py b/forms/colour_chart.py new file mode 100755 index 0000000..30d97d7 --- /dev/null +++ b/forms/colour_chart.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 + +import argparse +import math + +import fpdf +import strictyaml + + +class Chart: + COLUMNS=4 + ROWS=16 + + def __init__(self): + self.parser = self.get_parser() + self.args = self.parser.parse_args() + self.data = strictyaml.load(self.args.chart_data.read()).data + + def get_parser(self): + parser = argparse.ArgumentParser() + parser.add_argument( + "chart_data", + type=argparse.FileType("r") + ) + return parser + + def get_arranged_cells(self): + per_page = self.COLUMNS * self.ROWS + padded = self.data["colours"] + [{}] * ( + per_page - len(self.data["colours"]) % per_page + ) + pages = [ + padded[i * per_page:i * per_page + per_page] + for i in range(len(padded) // per_page) + ] + cells = [ + [ + [p[i + self.ROWS * j] for j in range(self.COLUMNS)] + for i in range(len(p) // self.COLUMNS) + ] + for p in pages + ] + return(cells) + + def write_pdf(self, fname): + pdf = fpdf.FPDF(format="A5") + + for p_num, page in enumerate(self.get_arranged_cells()): + pdf.add_page() + pdf.set_font("helvetica", size=12) + pdf.cell(64, 8, self.data["title"], align="C") + pdf.ln() + pdf.set_font("helvetica", "B", 12) + for j in range(self.COLUMNS): + pdf.cell(16, 8, str(j + p_num * self.COLUMNS),) + pdf.cell(16, 8, "") + pdf.ln() + for row in page: + for cell in row: + if cell: + pdf.set_fill_color(255,255,255) + if cell.get("bg"): + pdf.set_fill_color(*map(int, cell["bg"].split())) + pdf.cell(16, 8, "", border=1, fill=True) + pdf.cell(16, 8, cell["label"], ) + pdf.ln(10) + + pdf.output(fname) + + +if __name__ == "__main__": + Chart().write_pdf("asd.pdf") -- cgit v1.2.3