Created
October 4, 2010 07:33
-
-
Save podhmo/609350 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; redefine draw function then update display automatically | |
(extend gl.processing) | |
(use gauche.threads) | |
(define gen-timer-id | |
(let1 i 0 | |
(^ () (inc! i) i))) | |
(define (timer$ function) | |
(^ (delay-time) | |
(let1 id (gen-timer-id) | |
(define (function* v) | |
(function v) | |
(glut-timer-func delay-time function* v)) | |
(glut-timer-func delay-time function* id)))) | |
(define draw-update? #f) | |
(define draw #f) | |
(define-macro (redraw . actions) | |
`(begin | |
(set! draw | |
(draw$ (^ () ,@actions))) | |
(set! draw-update? #t))) | |
(define update-timer | |
(timer$ (^v (when draw-update? | |
(format (current-error-port) "draw is update") | |
(set! draw-update? #f) | |
(draw))))) | |
(define main | |
(setup$ (lambda () | |
(window 200 200 "animatin" 0 100) | |
(update-timer 100)))) | |
(define th (make-thread (cut main '()))) | |
(thread-start! th) | |
;;redrawの中を書き換えてgoshに送ると、変更が反映される。 | |
(redraw | |
(background 0.4 0.4 0.4) | |
(rect 100 100 30 30)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment