   (green  [n] (green (int->color n)))
   (blue   [n] (blue (int->color n)))
   (alpha  [n] (alpha (int->color n)))
-  (coerce [n] (int->color n)))
+  (coerce [n] (to-color (int->color n))))
 
 (extend-type java.lang.String
   IColor

  (alpha  [s] (alpha (string->color s)))
  (coerce [s] (to-color (string->color s))))

(extend-type clojure.lang.Keyword
  IColor
  (red    [s] (red (keyword->color s)))
  (green  [s] (green (keyword->color s)))
  (blue   [s] (blue (keyword->color s)))
  (alpha  [s] (alpha (keyword->color s)))
  (coerce [s] (keyword->color s)))

^:clj
(extend-type java.awt.Color

        (cons (mod n 256) ret)
        (quot n 256)))))

(defn string->color
  "Construct a tuple of RGB elements from a string."
  [s]
  (condp re-matches s
    #"#(.*)" :>> color-vec
    #"rgb\((.*),(.*),(.*)\)" :>> color-vec
    #"rgba\((.*),(.*),(.*),(.*)\)" :>> color-vec))

(defn keyword->color [k]
  (lindsay/swatch k))

(extend-type ^{:cljs cljs.core.PersistentVector} clojure.lang.PersistentVector
  IColor
