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

**URL:** <https://racket.discourse.group/t/til-how-to-convert-hex-triplet-to-racket-draw-color/3979>\
**Category:** General\
**Tags:** racketdraw, today-i-learnt\
**Created:** [October 21, 2025, 1:11pm UTC](https://racket.discourse.group/t/til-how-to-convert-hex-triplet-to-racket-draw-color/3979 "2025-10-21T13:11:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![spdegabrielle](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/spdegabrielle/32/95_2.png) [@spdegabrielle](https://racket.discourse.group/u/spdegabrielle)\
**Post date:** [October 21, 2025, 1:11pm UTC](https://racket.discourse.group/t/til-how-to-convert-hex-triplet-to-racket-draw-color/3979/1 "2025-10-21T13:11:45Z")

</div>

TIL how to convert a [hex triplet](https://www.w3.org/TR/REC-html40/types.html#h-6.5) to [`racket/draw` color](https://docs.racket-lang.org/draw/color_.html)

```scheme
;; 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))

```

```scheme
> (hex-triplet->color% #xdf542f) 
(object:color% ...)

```

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