#! /bin/bash -eu
# Last edited on 2026-06-02 16:25:50 by stolfi

# Makes about {ncolors} colors.

ncolors=$1; shift

umax=$(( ( ${ncolors} + 2 ) / 3 - 1 ))

for uh in $( count 1 ${ncolors} ); do
  h=$(( ( ${uh} * 1000 ) / ${ncolors} )) # Hue, times 1000
  
  if [[ $h -lt 333 ]]; then 
    u=$(( ${h} * 3 ));
    # Green to blue:
    r0=0;   g0=136; b0=0; 
    r1=61;  g1=31;  b1=255
  elif [[ $h -lt 667 ]]; then 
    u=$(( ( ${h} - 333) * 3 ))
    # Blue to red:
    r0=61;  g0=31;  b0=255
    r1=255; g1=7;   b1=7
  else
    u=$(( ( ${h} - 667) * 3 ))
    # Red to green:
    r0=255; g0=7;   b0=7
    r1=0;   g1=136; b1=0; 
  fi
  v=$(( 1000 - $u ))
  r=$(( ( ( ${r0} * $v ) + ( ${r1} * $u ) ) / 1000 )); 
  g=$(( ( ( ${g0} * $v ) + ( ${g1} * $u ) ) / 1000 )); 
  b=$(( ( ( ${b0} * $v ) + ( ${b1} * $u ) ) / 1000 )); 

  printf "#%02x%02x%02x\n" $r $g $b  
done    
