TIL how to convert hex triplet to `racket/draw` color

TIL how to convert a hex triplet to racket/draw color

;; Convert hex triplet to `racket/draw` color
;; hex-triplet->color% : hex -> colour%
(define (hex-triplet->color% x)
  (define-values [r g b]
    (values (arithmetic-shift x -16)
            (bitwise-and #x0000ff (arithmetic-shift x -8))
            (bitwise-and #x0000ff x)))
  (make-color r g b))
> (hex-triplet->color% #xdf542f) 
(object:color% ...)

from https://gitlab.com/bengreenman/pict-abbrevs/-/blob/master/private/pict-abbrevs.rkt#L188 thanks @ben_greenman

1 Like