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`; }