https://github.com/Zaku-eu/colourco.de/blob/be7a41500fd1b358...
or a convenient Emacs command/function:
(defun rgb-to-fgc (&optional background) "Returns a hex RGB triplet string for a chosen color or BACKGROUND." (interactive) (let ((background-rgb (color-name-to-rgb (or background (read-color nil t)))) (m (/ 96.0 255)) (foreground-rgb (mapcar (lambda (x) (+ x (if (> (apply #'max background-rgb) (- 1 m)) (* m -1) m))) background-rgb)) (foreground (apply #'color-rgb-to-hex foreground-rgb))) (message foreground) foreground))
https://github.com/Zaku-eu/colourco.de/blob/be7a41500fd1b358...
or a convenient Emacs command/function: