[Fluxus] rgb & hex colour conversion
nik gaffney
nik at fo.am
Thu Apr 9 01:49:51 PDT 2009
here are a pair of functions to convert between rgb and hex colour
descriptions, eg. "#ffffff" -> (255 255 255). im not sure where they
should be integrated into fluxus, as it could make sense to convert
either explicitly or transparently in any of the functions using colour
values.
;; convert a hex colour string to a list of 3 ints
(define (hex2rgb str)
(define (h2n h)
(string->number (string-append "#x" h) 16))
(let ((r (substring str 1 3))
(g (substring str 3 5))
(b (substring str 5 7)))
(list (h2n r) (h2n g) (h2n b))))
;; convert a list of 3 ints to a hex colour string
(define (rgb2hex r g b)
(string-append "#"
(number->string r 16)
(number->string g 16)
(number->string b 16)))
More information about the Fluxus
mailing list