From 20cc9710765ac27c878beb0abbcd43f709fe2509 Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Thu, 13 Mar 2025 09:19:06 +1100 Subject: [PATCH] Improved grammar --- poptimal.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/poptimal.js b/poptimal.js index fea8922..f7aa5a5 100644 --- a/poptimal.js +++ b/poptimal.js @@ -41,13 +41,17 @@ function randomise_params() { } function colour_to_text(d3color) { - return GetColorName(d3color.formatHex()).toLowerCase(); + const rawname = GetColorName(d3color.formatHex()).toLowerCase(); + // some return values are things like "cyan / aqua": take the first + const parts = rawname.split(/\//); + return parts[0].trim(); } function image_description(params) { const bgc = colour_to_text(params.background); const dotc = params.patterns.map((p) => colour_to_text(p.colour)); - return `A pattern of ${dotc[0]} and ${dotc[1]} dots on a ${bgc} background`; + const a = bgc.match(/^[aeiou]/) ? 'an' : 'a'; + return `A pattern of ${dotc[0]} and ${dotc[1]} dots on ${a} ${bgc} background`; }