outrun/pict3d-lib.rkt

22 lines
661 B
Racket
Raw Normal View History

2019-12-27 18:18:24 +01:00
#lang racket
(require pict3d)
2019-12-27 19:00:00 +01:00
(provide rgba-hex emitted-hex scale-number)
2019-12-27 18:18:24 +01:00
(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))))
2019-12-27 19:00:00 +01:00
(define (rgba-hex str [alpha 1])
(apply rgba `(,@(get-hex str) ,alpha)))
2019-12-27 18:18:24 +01:00
(define (emitted-hex str intensity)
(apply emitted `(,@(get-hex str) ,intensity)))
2019-12-27 19:00:00 +01:00
(define (scale-number s a1 a2 b1 b2)
(let ([a (- a2 a1)] [b (- b2 b1)])
(exact->inexact (+ b1 (/ (* (- s a1) b) a)))))