[plt-scheme] MrEd - Animated canvas

From: Laurent (Ouaibou at gmail.com)
Date: Tue Mar 6 16:25:13 EST 2007


I would like to carry out a wall breaker in scheme.
I started to write somes lines of code however I have some problems :
When I want to carry out an animation, i.e. to move for example a ball
of a point with another, a flutter occurs.

While seeking a little bit I saw that a double buffer had to be used,
but I do not know how that goes. Somebody could it explain me how to
simply carry out an animation without flutter in scheme ?

Here the piece of code which I produced:

(define CURSOR_POSITION 260)

; le timer fonctionne avec des millisecondes
(define WAIT-TIMER 10)

; redéfinition du déplacement du curseur
(define sens 1)
(define (move-cursor)
    (cond ((<= CURSOR_POSITION 0) (set! sens 1))
          ((>= CURSOR_POSITION 450) (set! sens -1)))
    (send canvas_1 refresh)))

; définition du timer de mouvement
(define my-timer (new timer% (notify-callback move-cursor) ))

; il faut modifier/augmenter le code de sortie du frame
; pour stopper le timer
(define my-frame%
  (class frame% ()
    (define/augment (on-close)
      (display "bye-bye")
      (send my-timer stop)
      (inner 0 on-close))


(define frame_1 (new my-frame% (label "Wall breaker")
                     (x 50) (y 50)
                     (min-height 600) (min-width 800)
                     (stretchable-width #f) (stretchable-height #f)))

(define menu_bar (new menu-bar% (parent frame_1)))
(define menu_1 (new menu% (parent menu_bar) (label "Wall breaker")))

(define hpanel_1 (new horizontal-panel% (parent frame_1) (alignment
'(center center))))
(define vpanel_1 (new vertical-panel% (parent hpanel_1)))
(define vpanel_2 (new vertical-panel% (parent hpanel_1)))
(define hpanel_2 (new horizontal-panel% (parent vpanel_1)))
(define hpanel_3 (new horizontal-panel% (parent vpanel_1)))

(define canvas_1 (new canvas% (parent vpanel_2)
                      (min-width 400)
                      (style '(border))
                      (paint-callback (lambda (obj dc)
                                        (send dc draw-rounded-
CURSOR_POSITION 570 150 15 5)

(send frame_1 show #t)
; démarrage du timer d'animation
(send my-timer start WAIT-TIMER)


Sorry for my bad English.


Posted on the users mailing list.