[plt-scheme] Re: MrEd - Animated canvas

From: Richard Cleis (rcleis at mac.com)
Date: Sat Mar 24 18:41:46 EDT 2007

On Mar 24, 2007, at 10:49 AM, Laurent wrote:

> Hi,
>
> I have two new questions :
>
> - To carry out my animation, i use a timer which calls a function
> which refresh my canvas. If i use :
>
>> (define (refresh canvas)
>>  (send canvas refresh))
>>
>> (define TIMER-ANIMATION (new timer% (notify-callback (refresh  
>> canvas_2))))
>
> This not perform, but if use this :
>
>> (define (refresh)
>>  (send canvas_2 refresh))
>
>> (define TIMER-ANIMATION (new timer% (notify-callback refresh)))
>
> It perform. I don't understand why.

Use the REPL (the command line) to see the difference:

1) Evaluate 'refresh' to see what it returns
2) Evaluate (refresh canvas_2) to see something completely different
3) Evaluate (lambda () (refresh canvas_2)) to see something like 1
4) Try (notify-callback (lambda () (refresh canvas_2)))

rac


>
> - My second question :
> The timer calls refresh who call paint-callback. In this method, i
> draw the beater, the bricks and the balls of my wall-breaker.
> However as my beater jerks at the time of displacement I wanted to use
> a thread. But if I use a thread the beater flick.
> I don't see why ?
>
>> (define canvas_2
>>  (new wb-canvas% (parent vpanel_2)
>>       (min-width 630)
>>       (style '(border no-autoclear))
>>       (paint-callback
>>        (lambda (canvas dc)
>>          (reset-offscreen! canvas_2)
>>          ;; On efface le buffer
>>         (send OFFSCREEN-DC clear)
>>          ;; On dessine les differents elements dans le buffer
>>          (send OFFSCREEN-DC draw-bitmap bg 0 0)
>>          (thread (lambda ()
>>                    (draw-batte OFFSCREEN-DC)))
>>          (draw-bricks OFFSCREEN-DC)
>>          (draw-balls OFFSCREEN-DC)
>>          ;; On copie l'image a l'écran
>>          (send dc draw-bitmap OFFSCREEN-BM 0 0)))))
>
> Thanks,
> Laurent
>
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.