22 lines
661 B
Racket
22 lines
661 B
Racket
#lang racket
|
|
(require pict3d)
|
|
|
|
(provide rgba-hex emitted-hex scale-number)
|
|
|
|
(define (get-hex str)
|
|
(let*-values ([(num) (string->number str 16)]
|
|
[(scale-n) (lambda (x) (/ x 255))]
|
|
[(num blue) (quotient/remainder num 256)]
|
|
[(red green) (quotient/remainder num 256)])
|
|
(list (scale-n red) (scale-n green) (scale-n blue))))
|
|
|
|
(define (rgba-hex str [alpha 1])
|
|
(apply rgba `(,@(get-hex str) ,alpha)))
|
|
(define (emitted-hex str intensity)
|
|
(apply emitted `(,@(get-hex str) ,intensity)))
|
|
|
|
|
|
(define (scale-number s a1 a2 b1 b2)
|
|
(let ([a (- a2 a1)] [b (- b2 b1)])
|
|
(exact->inexact (+ b1 (/ (* (- s a1) b) a)))))
|