;;;; 3d_clock.scm (use posix srfi-4 ezxdisp matchable) (define +pi+ 3.14159265358979323846) (define *ezx* (ezx-init 640 480 " 3D clock ")) (ezx-set-background *ezx* (make-ezx-color 1 1 1)) (ezx-select-layer *ezx* 3) (define *green* (make-ezx-color 0 1 0)) (define *blue* (make-ezx-color 0 0 1)) (define *black* (make-ezx-color 0 0 0)) (define *red* (make-ezx-color 1 0 0)) (ezx-line-3d *ezx* 120 120 20 -120 120 20 *green* 0) (ezx-line-3d *ezx* -120 120 20 -120 -120 20 *green* 0) (ezx-line-3d *ezx* -120 -120 20 120 -120 20 *green* 0) (ezx-line-3d *ezx* 120 -120 20 120 120 20 *green* 0) (ezx-line-3d *ezx* 120 120 -20 -120 120 -20 *blue* 0) (ezx-line-3d *ezx* -120 120 -20 -120 -120 -20 *blue* 0) (ezx-line-3d *ezx* -120 -120 -20 120 -120 -20 *blue* 0) (ezx-line-3d *ezx* 120 -120 -20 120 120 -20 *blue* 0) (do ([i 0 (add1 i)]) ((>= i 12)) (let ([x (* 100 (cos (- (/ (* 2 +pi+ i) 12) (/ +pi+ 2))))] [y (* 100 (sin (- (/ (* 2 +pi+ i) 12) (/ +pi+ 2))))] [z 0] ) (ezx-circle-3d *ezx* x y z (if (zero? (modulo i 3)) 15 20) (if (zero? i) *black* *red*)) ) ) (let ([a 0.001]) (ezx-select-layer *ezx* 4) (let loop () (match-let ([#(s m h _ _ _ _ _ _ _) (seconds->local-time (current-seconds))]) (ezx-wipe-layer *ezx* 4) (let ([x (* 40 (cos (- (/ (* -2 +pi+ (+ h (* m (/ 60.0)))) 12) (/ +pi+ 2))))] [y (* 40 (sin (- (/ (* -2 +pi+ (+ h (* m (/ 60.0)))) 12) (/ +pi+ 2))))] ) (ezx-line-3d *ezx* 0 0 0 x y 0 *black* 6) ) (let ([x (* 80 (cos (- (/ (* -2 +pi+ (+ m (* s (/ 60.0)))) 60) (/ +pi+ 2))))] [y (* 80 (sin (- (/ (* -2 +pi+ (+ m (* s (/ 60.0)))) 60) (/ +pi+ 2))))] ) (ezx-line-3d *ezx* 0 0 0 x y 0 *black* 6) ) (let ([x (* 80 (cos (- (/ (* -2 +pi+ s) 60.0) (/ +pi+ 2))))] [y (* 80 (sin (- (/ (* -2 +pi+ s) 60.0) (/ +pi+ 2))))] ) (ezx-line-3d *ezx* 0 0 0 x y 0 *black* 1) ) (let* ([x (sin (* a 0.12))] [y (sin (* a 0.79))] [z (+ (* (cos (* a 1.02)) 0.5) 0.5)] [r (sqrt (+ (* x x) (* y y) (* z z)))] [x (/ (* x 400) r)] [y (/ (* y 400) r)] [z (/ (* z 400) r)] ) (ezx-set-view-3d *ezx* x y z 0 0 0 5) (ezx-redraw *ezx*) ) (set! a (+ a 0.01)) (loop) ) ) )