examples/mood-ring.rkt
#lang planet dyoo/moby:3:9
  (require (planet dyoo/moby:3:9/phone/tilt))
  
  ; The world is a color.
  (define initial-world (make-color 0 0 0))
  
  ; tilt: world number number number -> world
  ; Tilting the phone adjusts the color.
  (define (tilt w azimuth pitch roll)
    (make-color (scale azimuth 360)
                (scale (+ pitch 90) 180)
                (scale (+ roll 90) 180)))
  
  ; scale-azimuth: number -> number
  ; Take a number going from 0-360 and scale it to a number between 0-255
  (define (scale n domain-bound)
    (inexact->exact (floor (* (/ n domain-bound) 255))))
  
  ; User interface.
  (define view (list (js-div '((id "background")))))
  
  (define (draw-html w) view)
  
  (define (draw-css w)
    (list (list "background"
                (list "background-color"
                      (format "rgb(~a, ~a, ~a)"
                              (color-red w)
                              (color-green w)
                              (color-blue w)))
                (list "width" "300")
                (list "height" "300"))))
  
  
  
  (big-bang initial-world
            (on-tilt tilt)
            (to-draw-page draw-html draw-css))