public
Last active

Old CRT televisions for Racket!

  • Download Gist
televise.rkt
Racket
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#lang racket
 
(require images/flomap
racket/draw
images/icons/style)
(provide (all-defined-out))
 
;; Turns 'bitmap' into an old CRT television-like version of itself.
(define (televise bitmap
#:color-offset [color-offset 2]
#:lens-bend [lens-bend (* 2/3 pi)])
(define imgfm (fmsqr (bitmap->flomap bitmap)))
;; fake gamma control
 
(define noise-offset-big
;; Approximating a square wave with power series (you can tell i
;; was in signals and systems class today)
;; This creates the "large" bands on the screen.
(flomap-normalize
(build-flomap 1 (flomap-width imgfm) (flomap-height imgfm)
(λ(k x y-not)
(define y (+ 12 (/ y-not 20)))
(+ (* 1/1 (sin (* 1 y)))
(* 1/3 (sin (* 3 y)))
(* 1/5 (sin (* 5 y)))
(* 1/7 (sin (* 7 y)))
(* 1/9 (sin (* 9 y))))))))
 
(define noise-offset
;; Smaller noise bands
(flomap-normalize
(build-flomap 1 (flomap-width imgfm) (flomap-height imgfm)
(λ(k x y)
(sin y)))))
 
(define (flomap-move fm dx dy)
;; Offset a flomap.
(flomap-inset fm dx dy (- dx) (- dy)))
 
;; Offset each channel of the RGB picture to make it look worse
(match-define (list imgfmr imgfmg imgfmb)
(map (curry flomap-ref-component imgfm) '(1 2 3)))
(define flomap-rgbshifted
(flomap-append-components (flomap-move imgfmr color-offset color-offset)
(flomap-move imgfmg (- color-offset) (- color-offset))
(flomap-move imgfmb (- color-offset) color-offset)))
 
(define screen
;; Build the actual CRT screen, without shading
(flomap-transform
;; Copy alpha channel from original:
(flomap-append-components (flomap-ref-component imgfm 0)
(fm+ (fm* noise-offset 0.1)
(fm+ (fm* noise-offset-big 0.1)
flomap-rgbshifted)))
;; Fisheye:
(flomap-projection-transform
(equal-area-projection lens-bend)
(stereographic-projection lens-bend)
#f)))
 
;; Finally, give glassy gloss to the TV screen.
(bitmap-render-icon (flomap->bitmap screen)
5/8 glass-icon-material))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.