Skip to content

Instantly share code, notes, and snippets.

@podhmo
Created October 4, 2010 07:33
Show Gist options
  • Save podhmo/609350 to your computer and use it in GitHub Desktop.
Save podhmo/609350 to your computer and use it in GitHub Desktop.
;;; 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